Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:58:09+00:00 2026-05-18T19:58:09+00:00

I have an activity that gets some data from the internet in background while

  • 0

I have an activity that gets some data from the internet in background while showing a progress dialog. When I get the data (or an error) I dismiss that dialog and show another one.

If for some reason the website takes too long to deliver the response (15+ seconds for example), the phone will turn off the screen. Now, while the screen is off, if I get a response and try to show a dialog, there will be an error (WindowManager$BadTokenException: Unable to add window — token android.os.BinderProxy@483fa968 is not valid; is your activity running?)

The reason of this problem is simple: when the screen turned off, another activity came to the foreground (keyguard or something).

Question: Now, whats the best method for invoking showDialog on an activity that we know that might not be running? (the activity was created but it’s not the one the user is interacting with.. in other words, it’s in stopped state).

I believe a similar behavior would happen if I clicked home and changed to the Home activity. (Although I can’t do this in my particular case because my activity would cancel the request and everything would shutdown correctly).

I don’t think that this makes any difference, but I reproduced this in Android 2.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:58:10+00:00Added an answer on May 18, 2026 at 7:58 pm

    Catch that exception and use some kind of persistent storage to save a flag that shows that you are waiting to show a dialog. Then in onResume() check that flag and if its true show the appropriate dialog. Something like this perhaps:

    try {
        getYourDataFromWeb();
        showDialog()
    } catch (BadTokenException e) {
        myPrefsEditor.putBoolean("FailedToShowDialog", true);
        myPrefsEditor.commit();
        e.printStackTrace();
    }
    

    Then in your onResume() method something like this:

    if(myPrefs.getBoolean("FailedToShowDialog", false) == true){
        showDialog();
        myPrefsEditor.putBoolean("FailedToShowDialog", false);
        myPrefsEditor.commit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.