What is this error, and why does it happen?
05-17 18:24:57.069: ERROR/WindowManager(18850): Activity com.mypkg.myP has leaked window com.android.internal.pol
if (mActivity != null && !mActivity.isFinishing() && mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
The solution is to call dismiss()
on the Dialog
you created in viewP.java:183
before exiting the Activity
, e.g. in onPause()
. All Window
s&Dialog
s should be closed before leaving an Activity
.
Try this code:
public class Sample extends Activity(){
@Override
public void onCreate(Bundle instance){
}
@Override
public void onStop() {
super.onStop();
progressdialog.dismiss(); // try this
}
}
You have to make Progressdialog
object in onPreExecute
method of AsyncTask
and you should dismiss
it on onPostExecute
method.
If you are using AsyncTask
, probably that log message can be deceptive. If you look up in your log, you might find another error, probably one in your doInBackground()
method of your AsyncTask
, that is making your current Activity
to blow up, and thus once the AsyncTask
comes back.. well, you know the rest. Some other users already explained that here :-)
This is not the answer to the question but it's relevant to the topic.
If the activity has defined an attribute in the Manifest
android:noHistory="true"
then after executing onPause(), the context of activity is lost. So all the view's using this context might give this error.