
This is a rather lazy solution but it works. Do not show dialog.& amp nbsp & amp nbsp I repeat, Do not show dialog. The isFinishing() method is basically used to check if the calling Activity is in the process of getting killed or has been killed. There are a lot of solutions to this issue and I will go through two of them in this post. If this happens, then trying to show a Dialog with that context object will throw the “Unable to add window - token is not valid” error. This could happen in the following scenario: You are performing a network operation and want to show a response Dialog when the operation returns, sometimes, by the time the Network operation returns with a response, the original calling Activity (context object) would have been either closed by the user or cleaned up by the system. This error occurs mainly when you try to show any UI component that requires a context object (Dialog, Snackbar, Toast, BottomSheetFragment, etc) with a context object that no longer exists. This exception is also similar to ” E/WindowManager: : Activity has leaked window that was originally added here”. $BadTokenException: Unable to add window - token is not valid is your activity running?Īt (ViewRootImpl.java:679)Īt (WindowManagerGlobal.java:342)Īt (WindowManagerImpl.java:93)Īt $TN.handleShow(Toast.java:459)Īt $TN$2.handleMessage(Toast.java:342)Īt android.os.Handler.dispatchMessage(Handler.java:102)Īt android.os.Looper.loop(Looper.java:154)Īt (ActivityThread.java:6119)Īt .invoke(Native Method)Īt .ZygoteInit$n(ZygoteInit.java:886) at .ZygoteInit.main(ZygoteInit.java:776)
