
No matter what TYPE I use for the LayoutParams, I always get this crash. avity = Gravity.TOP | Gravity.START Įxception stacktrace: Caused by: $BadTokenException: Unable to add window - token null is not valid is your activity running?Īt (ViewRootImpl.java:764Īt (WindowManagerGlobal.java:356)Īt (WindowManagerImpl.java:92) I have added the 'SYSTEMALERTWINDOW' permission and I have enabled 'Draw over other apps' in app info.

RelativeLayout overlay = (RelativeLayout) inflater.inflate(R.layout.button_main, null) įinal WindowManager.LayoutParams params = WindowManager.addView () causes BadTokenException Ask Question 2 I'm trying to create an overlay window but when I try to add the view to the WindowManager, it gives me an exception. LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)

Fatal Exception: $BadTokenException: Unable to add window - token is not valid is your activity running?Īt (ViewRootImpl.java:1444)Īt (WindowManagerGlobal.java:469)Īt (WindowManagerImpl.java:114)Īt (Dialog.java:505)Īt (ProgressDialog.java:225)Īt (ProgressDialog.java:199)Īt .ProgressDialogShow2(Common.java:740)Īt .ProgressDialogShow(Common.java:729)Īt ._maaksynchroon(synchroniseer.java:403)Īt .invoke(Method.java)Īt .raiseEvent2(BA.java:213)Īt $11.run(Common.java:1178)Īt android.os.Handler.handleCallback(Handler.java:938)Īt android.os.Handler.dispatchMessage(Handler.java:99)Īt android.os.Looper.loop(Looper.java:246)Īt (ActivityThread.java:8538)Īt .RuntimeInit$n(RuntimeInit.java:602)Īt .ZygoteInit.main(ZygoteInit.I'm trying to create an overlay window but when I try to add the view to the WindowManager, it gives me an exception.
