我有一個菜單按鈕,當我單擊它時,它會向雲發送一些數據。在發送數據時,我會顯示一個進度對話框。每件事情都順其自然,似乎很好,我可以多次按下按鈕,並將數據正確發送到雲端。 但是當我去退出活動我得到一個錯誤,說有一個窗口泄漏:即使在調用解除後也會出現進度對話框泄漏的窗口錯誤
com.android.internal.policy.impl.PhoneWindow$DecorView{4321fd38 V.E..... R......D 0,0-1026,288} that was originally added here
的「這裏」指的是,當我饞我的進度對話框。
這裏是我的代碼:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
progressDialog = ProgressDialog.show(CruiseDetailRollCallActivity.this, "", "Loading...", true);//set up & show progress dialog
switch(item.getItemId()){
case R.id.menu_roll_call_opt_in:
//saveing something into Parse -- (a database online, check Parse.com if you want more info, but just treat this like I am saving something into the cloud)
currentUser.put("somethingBoolean", false);
currentUser.saveInBackground(new SaveCallback(){
@Override
public void done(ParseException e) { //once data has been put into the cloud
progressDialog.dismiss();//dismiss the dialog
supportInvalidateOptionsMenu();//refreshes the options menu
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
我應該指出,這不是我的崩潰申請,但僅僅是顯示錯誤。我不知道爲什麼會發生,我覺得我不應該忽略它。
編輯:發現我的錯誤。這是失敗的,因爲作品是因爲我在回到操作欄上,並且進度對話框將被創建,但從未被解僱,因爲它只是在完成的代碼中被解散。
你應該解僱'進展Dialog'在'的onStop()。' –
@SimplePlan見我在下面對你的回答發表評論。 onStop()是可驅動的,取決於操作系統決定做什麼,onStop()可能永遠不會被執行。 – mttdbrd