Activity leaked into the window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0

I am developing a feedback application, when I click the submitnow button, I get the following error

Activity leaked out the window

com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0 

Below is my code, please help me.

 public class SignOut_Activity extends SherlockActivity implements OnClickListener { Button btnSubmitNow, btnSubmitLater; ProgressDialog progressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.signout); ((TextView) findViewById(R.id.tvSubTitle)) .setText(StoresListAdapter.StoreName); btnSubmitNow = (Button) findViewById(R.id.btnSubmitNow); btnSubmitLater = (Button) findViewById(R.id.btnSubmitLater); btnSubmitNow.setOnClickListener(this); btnSubmitLater.setOnClickListener(this); progressDialog = new ProgressDialog(SignOut_Activity.this); progressDialog.setMessage("Uploading data, please wait..."); } @Override public boolean onOptionsItemSelected( com.actionbarsherlock.view.MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // app icon in action bar clicked; finish activity to go home finish(); break; default: break; } return super.onOptionsItemSelected(item); } @Override public void onResume() { super.onResume(); // Set title getSupportActionBar().setTitle("Sign Out"); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnSubmitNow: // Submit now // Sample upload image UploadImage.uploadImage("testimage"); new AsyncTask<Void, Void, Void>() { // called before execution // main/UI thread protected void onPreExecute() { progressDialog.show(); }; @Override protected Void doInBackground(Void... params) { // Submit the store data StoreData.postData(StoreList_Activity.storesList .get(StoresListAdapter.Position)); return null; } // on store data uploaded // main/UI thread protected void onPostExecute(Void result) { progressDialog.dismiss(); setSignOut(); StoreList_Activity.storesList .get(StoresListAdapter.Position).isSubmitted = true; SignOut_Activity.this.finish(); }; }.execute(); break; case R.id.btnSubmitLater: // Submit later setSignOut(); StoreList_Activity.storesList.get(StoresListAdapter.Position).isSubmitLater = true; VisitOps_Activity.isSubmitLater = true; SignOut_Activity.this.finish(); break; default: break; } } @SuppressLint("SimpleDateFormat") private void setSignOut() { VisitOp visitOp10 = new VisitOp(); visitOp10.setName("Sign Out"); visitOp10.setStatus(""); SampleData.visitOpsList.add(visitOp10); if (VisitOps_Activity.VisitOps.SignOut == null) VisitOps_Activity.VisitOps.SignOut = new SignOut(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); String currentDateandTime = sdf.format(new Date()); VisitOps_Activity.VisitOps.SignOut.SignOutTime = "Out: " + currentDateandTime; } } 
+7
java android android-dialogfragment android-dialog
source share
5 answers

The leak comes because you keep the link to the activity after it is destroyed, so use

 if(progressDialog !=null) { progressDialog = null; } progressDialog = new ProgressDialog(this.getApplicationContext()); progressDialog.setMessage("Uploading data, please wait..."); 

OR

use it, it will help

 @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnSubmitNow: // Submit now // Sample upload image UploadImage.uploadImage("testimage"); new AsyncTask<Void, Void, Void>() { // called before execution // main/UI thread protected void onPreExecute() { progressDialog = new ProgressDialog(SignOut_Activity.this); progressDialog.setMessage("Uploading data, please wait..."); progressDialog.show(); }; @Override protected Void doInBackground(Void... params) { // Submit the store data StoreData.postData(StoreList_Activity.storesList .get(StoresListAdapter.Position)); return null; } // on store data uploaded // main/UI thread protected void onPostExecute(Void result) { progressDialog.dismiss(); setSignOut(); StoreList_Activity.storesList .get(StoresListAdapter.Position).isSubmitted = true; SignOut_Activity.this.finish(); }; }.execute(); 
+11
source share

Why is this error ...?

this error occurs if you keep a link to an unused activity

Decision

remove the link to the progress bar, dialogue ..... etc. after use.

rejecting them or making them equal to zero

you can come close to this when you no longer need it

It is recommended to put it in onStop

  @Override protected void onStop() { super.onStop(); if(_dialog.isShowing()){ _dialog.dismiss(); } if(_dialog != null){ _dialog = null; } } 
+4
source share

Reset the dialog after using it, it will not let your application crash.

 dialog.dismiss(); 
+3
source share

use this code progressDialog.dismiss();

+2
source share

Make sure you cancel () the dialog after using the dialog and before starting the next background process.

+1
source share

All Articles