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

  • Home
  • SEARCH
  • 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 6013581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:34:11+00:00 2026-05-23T02:34:11+00:00

I have a problem that causes me some problems when a user (or another

  • 0

I have a problem that causes me some problems when a user (or another app, like the phone-application) pushes my application to the background.

My application does following:

  1. A User can enter some information that is supposed to be pushed to a server.
  2. When the user clicks “Send” i open a managed ProgressDialog and start an AsyncTask that performs the server communication.
  3. When server communication is complete the AsyncTask reports back to my Activity where i perform a dismissDialog().
  4. Directly after dismissDialog(), I will show another managed dialog using showDialog() that will inform the user about whether the submission was ok or if it failed.

This all works perfectly without any issues; however, when a call happens to come while the AsyncTask is running I get (seemingly random) one of these results:

  1. The activity holding the managed dialog is dismissed completely and the previous view from the stack is presented when I come back.
  2. The activity holding the managed dialog is still on screen, but it is grayed out without showing a dialog. The only way to fix this is to rotate the phone at which point it shows the “Submission sent”-dialog exactly the way it should and everything is ok after that.

All this happens without any warning messages so I get absolutely no clues as to why Android is behaving this way.

I know a way around this and that is to cancel the AsyncTask (so no dialogs are shown at the end). However, in this very use-case the requirements are that the app has to try to complete the server transaction so that there is as little confusion as possible (i.e. the user wondering if it was really sent or not).

Has anybody else had this issue and knows a way around?

  • 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-23T02:34:11+00:00Added an answer on May 23, 2026 at 2:34 am

    I see recommendations to hold a reference to the asynch task in onRetainNonConfigurationInstance

    What to do with AsyncTask in onPause()?

    Or implement a bus:

    https://github.com/commonsguy/cwac-bus/tree

    EDIT: The complexity of your challenge is two fold:

    1) saving and restoring state of your app on a kill such as when there is an incoming phone call

    https://sites.google.com/site/jalcomputing/home/mac-osx-android-programming-tutorial/saving-instance-state

    2) somehow continuing the asyncTask on kill instead of canceling it onPause

    https://sites.google.com/site/jalcomputing/home/mac-osx-android-programming-tutorial/asynch

    Both of these are significant challenges alone, and trying to fix both at the same time would give me a headache. In fact, I am getting a headache just thinking on it 🙂 One clue is that you say the dialog returns on orientation change. This MAY be due to the fact that using the standard architecture for dialogs, the OS handles saving and restoring the state of dialogs for you on orientation change.

    [EDIT] See CommonsWare

    @Override
    public Object onRetainNonConfigurationInstance() {
        task.detach();
        return(task);
    }
    

    and

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        bar=(ProgressBar)findViewById(R.id.progress);   
        task=(RotationAwareTask)getLastNonConfigurationInstance();  
        if (task==null) {
            task=new RotationAwareTask(this);
            task.execute();
        }
        else {
            task.attach(this);
            updateProgress(task.getProgress());
            if (task.getProgress()>=100) {
                markAsDone();
            }
        }
    }
    

    where task is an instance of

    static class RotationAwareTask extends AsyncTask<Void, Void, Void> {
    

    I see no reason why this would not work for all types of soft kills, but on a hard kill, well, you get killed. Dead is dead 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I would like have solved via a SQL query.
I have a problem that seems like its a result of a deadlock-situation. Whe
The problem im having is that I have a table that when a user
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I feel is best implimented in a stand alone
(I have a problem that I illustrated in this question but had no correct
I have a problem that output string must be utf8-formatted, I am writing currently
We have the problem that we have the open project files in our SVN

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.