0

I am seeing this IllegalStateException crash in Toast on Android 8.0 and 8.1 in the field. Devices: LGE LG Stylo 4 (cv7a), Android 8.1, Huawei Mate 10 Pro (HWBLA), Android 8.0.

Seems to bear many similarities to android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@b0baaa1 is not valid; is your activity running?

but a different exception. Sounds like it cannot be fixed with try/catch in your own code. Anyone else run across this or have a fix? (Note: I suspect the replacement toastCompat library mentioned at above link may work, but I have not tried it yet).

java.lang.IllegalStateException:
at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:349) at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:94) at android.widget.Toast$TN.handleShow (Toast.java:574) at android.widget.Toast$TN$1.handleMessage (Toast.java:477) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:6651) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:810)

Venu G.
  • 427
  • 1
  • 5
  • 10
  • Can you add the code block which is causing `Exception` ? – ADM Feb 11 '19 at 04:51
  • Code issuing exception is within Android's Toast code. – Venu G. Feb 11 '19 at 04:53
  • Yeah i asked for code block not a single line of code . – ADM Feb 11 '19 at 04:53
  • There should be some text that accompanied the IllegalStateException. Can you post that as well? The code for WindowManagerGlobal#addView does throw an IllegalStateException if the view that is being added has already been added to the window manager. – Michael Krause Feb 11 '19 at 04:55
  • [this](https://stackoverflow.com/questions/51956971/illegalstateexception-of-toast-view-on-android-p-preview) might be helpful to you – Tejas Pandya Feb 11 '19 at 04:56
  • @ADM, not quite sure what you are asking. I use Toast in many areas of my code. Cannot determine which of these Toast calls results in the exception above, because the exception is not issued from within any of my own methods. My code never calls Toast.handleShow(). It is done by the Toast class library itself. – Venu G. Feb 11 '19 at 04:58
  • Thanks, @TejasPandya, I will study that.. but note that this is coming from API 16, 27 (not 28). – Venu G. Feb 11 '19 at 05:01
  • @Micheal Kraus, this came from crash in field - all the info I have I have posted above. The toast (most likely) is called from a background service using the applicationContext, and I am cancelling any existing toasts before displaying a new one. – Venu G. Feb 11 '19 at 05:12

0 Answers0