0

This crash occurs many times but I do not understand what is the exact issue.

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@42383ff8 is not valid; is your activity running?
   at android.view.ViewRootImpl.setView(ViewRootImpl.java:536)
   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2852)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
   at android.app.ActivityThread.access$800(ActivityThread.java:135)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5017)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
   at dalvik.system.NativeStart.main(NativeStart.java)

I check every time before opening dialog that if the activity is finishing or not, but still this crash occurs. I found these crashes in Crashlytics. I am unable to reproduce in my test devices. Have anybody any idea?

Crash report is not showing crash at builder.show() or dialog.show().

private void showIntroText() {
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
            .setMessage(R.string.msg_intro)
            .create();
    if (!isFinishing()) {
        alertDialog.show();
        final Handler handler = new Handler();
        handler.postDelayed(() -> {
            if (!MainActivity.this.isFinishing() && alertDialog.isShowing()) {
                alertDialog.dismiss();
            }
        }, 3000);
    }
}
vidha
  • 1,257
  • 2
  • 14
  • 22
  • 1
    Possible duplicate of ["android.view.WindowManager$BadTokenException: Unable to add window" on buider.show()](https://stackoverflow.com/questions/18662239/android-view-windowmanagerbadtokenexception-unable-to-add-window-on-buider-s) – ADM Mar 22 '18 at 07:50
  • Without any code we can not make any assumption . – ADM Mar 22 '18 at 07:51
  • How did you check if the activity is finishing or not? – Jordan Mar 22 '18 at 07:52
  • depict your activity/fragment from where you are opening dialog. – Radhey Mar 22 '18 at 07:57
  • @Jordan, Radhey, I added java code in question. – vidha Mar 22 '18 at 08:00
  • put `showIntroText()` this method in runOnUI thread and let me know.. – Radhey Mar 22 '18 at 08:06
  • and remove handler stuff(dismiss dialog simply). It doesn't make much sense here.. – Radhey Mar 22 '18 at 08:08
  • @Radhey I put handler to automatically dismiss dialog after 3 seconds. – vidha Mar 22 '18 at 08:18
  • what is `!isFinishing()` and `!MainActivity.this.isFinishing()` check for? is it from your `MainActivity` running or not (for the same activity) ? – Radhey Mar 22 '18 at 09:51
  • Are you finishing the activity after dialogue is dismissed? Is it your splash activity or something like that? – Jordan Mar 22 '18 at 10:46
  • The code snippet that you have shared in the question works perfectly! There is something else that you are trying to implement alongside it which is causing this error. – Jordan Mar 22 '18 at 11:06

0 Answers0