Activity has leaked window that was originally added

后端 未结 30 3050
野趣味
野趣味 2020-11-21 05:48

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         


        
相关标签:
30条回答
  • 2020-11-21 06:23
      if (mActivity != null && !mActivity.isFinishing() && mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    
    0 讨论(0)
  • 2020-11-21 06:25

    The solution is to call dismiss() on the Dialog you created in viewP.java:183 before exiting the Activity, e.g. in onPause(). All Windows&Dialogs should be closed before leaving an Activity.

    0 讨论(0)
  • 2020-11-21 06:25

    Try this code:

    public class Sample extends Activity(){
    @Override
     public void onCreate(Bundle instance){
    
    }
     @Override
        public void onStop() {
            super.onStop();
          progressdialog.dismiss(); // try this
        }
    
    }
    
    0 讨论(0)
  • 2020-11-21 06:26

    You have to make Progressdialog object in onPreExecute method of AsyncTask and you should dismiss it on onPostExecute method.

    0 讨论(0)
  • 2020-11-21 06:27

    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 :-)

    0 讨论(0)
  • 2020-11-21 06:27

    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.

    0 讨论(0)
提交回复
热议问题