Android : WindowManager$BadTokenException AlertDialog

on Friday, September 12, 2014


Two users sent me the following bug reports.


First on Android 2.3.7:



android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4051c190 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:527)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:180)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:244)
at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:533)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)


Second for Android 4.0++



android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4132f030 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:646)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:644)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)


It seems that the way i use alertdialog is false.... Can anyone show me the best way to use alertdialog?


0 comments:

Post a Comment