11/8/2023 0 Comments Android windowmanager addview![]() ![]() ![]() I pass my activity’s reference to the task’s constructor using “this”, storing it in an instance and using it to create a dialog. Here I want to show an AlertDialog in onPostExecute method of my AsyncTask. Let us first create this scenario which causes the exception to be thrown, by using the following code. Please search in the settings for this permission and allow it for your app. If you are trying to modify the UI from background thread (usually from onPostExecute() of AsyncTask) and if the activity enters finishing stage i.e.) explicitly calling finish(), user pressing home or back button or activity clean up made by Android then you get this error.Ī$BadTokenException: Unable to add window - token is not valid is your activity running?Īt (ViewRootImpl.java:585)Īt (WindowManagerImpl.java:326)Īt (WindowManagerImpl.java:224)Ī$CompatModeWrapper.addView(WindowManagerImpl.java:149)Īt $LocalWindowManager.addView(Window.java:547)Īt (Dialog.java:277)Ĭom.$LongTask.onPostExecute(MainActivity.java:72)Ĭom.$LongTask.onPostExecute(MainActivity.java:1)Īt android.os.AsyncTask.finish(AsyncTask.java:631)Īt android.os.AsyncTask.access$600(AsyncTask.java:177)Īt android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)Īt android.os.Handler.dispatchMessage(Handler.java:99)Īt android.os.Looper.loop(Looper.java:137)Īt (ActivityThread.java:4745)Īt .invokeNative(Native Method)Īt .invoke(Method.java:511)Ĭom.ZygoteInit$n(ZygoteInit.java:786)Īt .ZygoteInit.main(ZygoteInit.java:553)Īt (Native Method) It requires draw over other apps permission by the user. This exception occurs when the app is trying to notify the user from the background thread (AsyncTask) by opening a Dialog. I faced this exception in one of my application and after a long research I found a solution for this problem. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |