Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle AsyncTask onPostExecute when paused to avoid IllegalStateException
    primarykey
    data
    text
    <p>I appreciate the numerous postings regarding AsyncTask on a rotation change. I have the following problem when using the compatability lib and trying to dismiss a <code>DialogFragment</code> in <code>onPostExecute</code>.</p> <p>I have a fragment which fires of an AsyncTask which displays a progress <code>DialogFragment</code>, then in <code>onPostExecute</code> dismisses the dialog and then potentially throws up another <code>DialogFragment</code>.</p> <p>If when the progress dialog is being displayed I put the application into the background I get the following for my fragment: </p> <p>1) <code>onPause</code> </p> <p>2) <code>onSaveInstanceState</code></p> <p>3) <code>onPostExecute</code> in which I try to dismiss and invoke a dialog.</p> <p>I get an <code>IllegalStateException</code> because I'm trying to effectively commit a transaction when the activity has saved its state and I understand this.</p> <p>On a rotation I've assumed (perhaps incorrectly) that I wouldn't get an <code>onPostExecute</code> until the activity has been recreated. However, when putting the application into the background I assumed (definitely incorrectly) that the <code>onPostExectute</code> wouldn't get called while the fragment/activity was paused.</p> <p>My question is, is my solution to simply detect in <code>onPostExecute</code> that the fragment/activity is paused and simply perform what I need to do in <code>onResume</code> instead? Seems somewhat ugly to me.</p> <p>Thanks in advance, peter.</p> <p><strong>Edit 1</strong></p> <p>Need to support 2.1 and above</p> <p><strong>Edit 2</strong></p> <p>I have considered showing the dialog using <code>FragmentTransaction:add</code> and <code>FragmentTransaction:commitAllowingStateLoss</code>however this isn't without its problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload