2016-03-02 94 views
3

權後,我解決我的第一個問題這一個出現:(請幫我解決這個問題..安卓:窗口管理器:Android設備上查看窗口泄露

十二月3日至2日:47:02.785 9439-9439/com.ucu.ccs.classrecord E/WindowManager:android.view.WindowLeaked:Activity com.ucu.ccs.classrecord.Login已泄露窗口 com.android.internal.policy.impl.PhoneWindow $ DecorView {6d17cc4 VE .... R ...... D 0,0-1002,348}最初在這裏添加的 at android.view.ViewRootImpl。(ViewRootImpl.java:465) at android.view.WindowManagerGlobal.addView( WindowManagerGlobal.java :277) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.Dialog.show(Dialog.java:312) at com.ucu.ccs.classrecord.Login $ AttemptLogin.onPreExecute (Login.java:158) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587) at android.os.AsyncTask.execute(AsyncTask.java:535) at com.ucu.ccs.classrecord.Login .isOnline(Login.java:113) at com.ucu.ccs.classrecord.Login $ 1.onClick(Login.java:73) at android.view.View.performClick(View.java:5197) at android。 View.View $ PerformClick.run(View.java:20926) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchM essage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method。在com.android.internal.os.ZygoteInit上調用(Native Method) .internal.os.ZygoteInit.main(ZygoteInit.java:1194)

這裏是我的代碼:

buttonLogin.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       String instructor_id = editUser.getText().toString().trim(); 
       String password = editPass.getText().toString().trim(); 

       SharedPreferences preferences = getSharedPreferences("MyApp", MODE_PRIVATE); 
       preferences.edit().putString("password", password).commit(); 
       preferences.edit().putString("inst_id", instructor_id).commit(); 

       if (editUser.getText().toString().equals("") || editPass.getText().toString().equals("")){ 
        Toast.makeText(getApplicationContext(),"Please enter Instructor ID and Password", Toast.LENGTH_LONG).show(); 
       }else { 
        isOnline(); 
       } 

      } 
     }); 

public boolean isOnline(){ 
     ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
     NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); 
     if (networkInfo != null && networkInfo.isConnectedOrConnecting()){ 
      new AttemptLogin().execute(); 
     }else { 
      checkInternet(); 
     } 
     return false; 
    } 

class AttemptLogin extends AsyncTask<String, String, String> { 
     boolean failure = false; 
     String inst_id = editUser.getText().toString(); 
     String password = editPass.getText().toString(); 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(Login.this); 
      pDialog.setMessage("Attempting login..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(true); 
      pDialog.show(); 
     } 

     @Override 
     protected String doInBackground(String... params) { 
      int success; 
      try{ 
       List<NameValuePair> mList = new ArrayList<NameValuePair>(); 
       mList.add(new BasicNameValuePair("instructor_id", inst_id)); 
       mList.add(new BasicNameValuePair("password", password)); 

       Log.d("request!", "starting"); 

       JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", mList); 
       Log.d("Login attempt", json.toString()); 

       success = json.getInt(TAG_SUCCESS); 
       if (success == 1) { 
        Log.d("Login Successful!", json.toString()); 
        Intent i = new Intent(Login.this, MainActivity.class); 
        startActivity(i); 
        //finish(); 
        return json.getString(TAG_MESSAGE); 
       }else{ 
        Log.d("Login Failure!", json.getString(TAG_MESSAGE)); 
        return json.getString(TAG_MESSAGE); 
       } 

      }catch (JSONException e){ 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(String s) { 
      super.onPostExecute(s); 
      session.setLogin(true); 
      pDialog.dismiss(); 
      if (s != null){ 
       Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 
+0

你做了什麼?我的意思是你點擊按鈕後做了什麼? –

+0

我只是單擊按鈕,然後進度對話框出現後,它完成處理應用程序崩潰 – CallMeJeo

+0

嘗試我的解決方案。 –

回答

15

如果您的活動已被破壞但仍然顯示對話框,則會發生此錯誤。所以你已經添加這些代碼在你的活動的onDestroy()

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    if (dialog != null) { 
     dialog.dismiss(); 
     dialog = null; 
    } 
} 

希望這對你有用。

0

您試圖在退出活動後顯示對話框。 在你的doInBackground當你正在轉移你的活動時關閉對話框startActivity(i) 試試這個,讓我知道它是否有效。

0

其實你的活動正在完成一些如何,所以你需要關閉對話框。

在的onPause()添加下面的代碼

if(isFinishing()){ 
    if (pDialog!= null) { 
     pDialog.dismiss(); 
     pDialog= null; 
    } 
} 
相關問題