Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue on Android 6.0.1 "Fatal Exception: android.view.WindowManager$BadTokenException"

I'm seeing this error in our crash logging coming from only Android 6.0.1 devices, but not device specific.

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:849)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:337)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
       at android.widget.PopupWindow.invokePopup(PopupWindow.java:1329)
       at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1077)
       at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1035)
       at com.android.internal.widget.FloatingToolbar$FloatingToolbarPopup.show(FloatingToolbar.java:563)
       at com.android.internal.widget.FloatingToolbar.show(FloatingToolbar.java:214)
       at com.android.internal.view.FloatingActionMode$FloatingToolbarVisibilityHelper.updateToolbarVisibility(FloatingActionMode.java:411)
       at com.android.internal.view.FloatingActionMode$1.run(FloatingActionMode.java:65)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7229)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Does anyone know the cause/solution for this issue? It seems to occur relatively infrequently.

like image 669
RyanCheu Avatar asked Oct 19 '22 06:10

RyanCheu


1 Answers

Have the same problem only on Samsung devices with Android 6.0.1 and above. Being able to reproduce it.

The problem is with the new floating action mode (floating toolbar)

It's happening when a user selects some text on the screen (floating toolbar appeared), goes to the previous activity (closes the current activity) and then, as far as I understood, android OS is trying to recreate it (because it wasn't properly closed) using the object of activity that has been destroyed.

The solution is to deal with new ActionMode properly and to close it before closing the activity.

like image 129
nicolausYes Avatar answered Nov 02 '22 05:11

nicolausYes