title: Bad token exception - Unable to add window (Marshmallow - Floating toolbar)
body: <p>I've been struggling to find out the reason of this exception for a while, I've never been able to reproduce myself but some of my customers are experiencing it. It only happens on Android 6.0.1, and since the crash occurrs within the SDK itself it's quite hard to figure out how it happens.</p>
  
  <p>Other solutions regarding this problems have not helped, such as:</p>
  
  <p><a href="https://stackoverflow.com/questions/8803915/window-manager-bad-token-exception">window manager bad token exception</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18662239/android-view-windowmanagerbadtokenexception-unable-to-add-window-on-buider-s">&quot;android.view.WindowManager$BadTokenException: Unable to add window&quot; on buider.show()</a></p>
  
  <p>I am using DialogFragments and AlertDialogs, I guess it could be the core issue but it just doesn't add up since it only affects Marshmallow users.</p>
  
  <pre><code>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:561)
         at com.android.internal.widget.FloatingToolbar.show(FloatingToolbar.java:212)
         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:7224)
         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)
  </code></pre>