Failed to add window token android.os.BinderProxy@4250d6d8 is invalid; is your activity working?

One user sent me this crash report yesterday:

 android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4250d6d8 is not valid; is your activity running?
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:698)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
    at android.view.Window$LocalWindowManager.addView(Window.java:552)
    at android.app.Dialog.show(Dialog.java:277)
    at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:833)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
    at dalvik.system.NativeStart.main(Native Method)

      

So I searched and it says the solution is to change this

to Activity.this

But this solution didn't work even if I use the following code:

//Oncreate Method.....

     button.setOnClickListener(new OnClickListener(){

                        @Override
                        public void onClick(View v) {

         AlertDialog.Builder alertd = new AlertDialog.Builder(MainActivity.this);

         alertd.setMessage("StackOverflow");

         alertd.setTitle("Example");

         AlertDialog alertd2 = alertd.create();

         alertd2.show();
        }

                      });

      

Should I change something?

+3


source to share


1 answer


Finally I found a solution. The problem is your alert is trying to show even though your activity has ended.

So what you have to do is check if the action ends before showing the alert. To do this, isFinishing () is defined in the Activity class .

Here's what you do:



 if(!isFinishing())
 {
     alert.show();
 }

      

Good luck.

+6


source







All Articles