My app frequently throws android.view.WindowLeaked exception -- -
my app throws exception below:
e/windowmanager( 6282): android.view.windowleaked: activity com.myactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview@4479b710 added here
the app shows progress dialog when main activity starts , starts task. when task done, dismiss progress dialog.
my code below. can me?
public class myactivity extends activity { private static int id_dialog_progress = 2001; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_activity); showdialog(id_dialog_progress); new mytask().execute(null, null, null); } @override protected dialog oncreatedialog(int id) { if (id == id_dialog_progress) { progressdialog loadingdialog = new progressdialog(this); loadingdialog.settitle(""); loadingdialog.setmessage(""); loadingdialog.setindeterminate(true); loadingdialog.setcancelable(false); return loadingdialog; } return super.oncreatedialog(id); } private class mytask extends asynctask<void, void, void> { @override protected void doinbackground(void... arg0) { /* expensive here...*/ /* start other activity*/ intent intent = new intent(myactivity.this, otheractivity.class); startactivityforresult(intent, 1000); } return null; } protected void onpostexecute(void arg0) { dismissdialog(id_dialog_progress); } } }
most of time, exception thrown showdialog() call. other time, exception thrown dismissdialog() call.
thank in advance!
you're starting new activity in doinbackground()
before dismiss dialog in onpostexecute()
, causing dialog leak. move
intent intent = new intent(myactivity.this, otheractivity.class); startactivityforresult(intent, 1000);
to onpostexecute()
after dismissdialog()
call , see happens.
Comments
Post a Comment