I have an activity that receives some data from the Internet in the background, showing a progress dialog. When I get the data (or error), I dismiss this dialog and show another one.
If for any reason the website takes too long to deliver a response (for example, more than 15 seconds), the phone will turn off the screen. Now, when the screen is off, if I get an answer and try to show a dialog, an error will appear (WindowManager $ BadTokenException: could not add the window marker android.os.BinderProxy@483fa968 invalid, is this your activity?)
The reason for this problem is simple: when the screen turned off, another activity came to the fore (keyguard or something else).
Question: Now, what is the best method to call showDialog for an action that we know that might not work? (the action was created, but this is not the one with which the user interacts .. in other words, he is in a stop state).
I believe that this behavior will happen if I clicked on the house and switched to the main activity. (Although I cannot do this in my particular case, because my activity will cancel the request and everything will be completed normally).
I don't think it matters, but I reproduced it in Android 2.1
android
Pedro loureiro
source share