Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask doesn't run sometimes despite state being RUNNING?
    text
    copied!<p>In my application I use an AsyncTask on start up of my Activity to fetch the ringtone of a particular contact.</p> <p>It works normally but I have noticed that if the application is stopped twice before the AsyncTask gets to the doInBackground method then when the Activity starts again the AsyncTask fails to run properly, only getting to the onPreExecute() method.</p> <p>Here is my code:</p> <p>The AsyncTask itself:</p> <hr> <pre><code>private class SelectRingtoneTask extends AsyncTask&lt;String, Void, Void&gt; { // can use UI thread here protected void onPreExecute() { Log.d("cda", "Into selectRingToneTask - onPreExecute() - " + selectRingtoneFinished); } // automatically done on worker thread (separate from UI thread) protected Void doInBackground(final String... args) { Log.d("cda", "Into selectRingToneTask - !!!!!!!!!!!!!!!"); getRingTone(); return null; } // can use UI thread here protected void onPostExecute(final Void unused) { selectRingtoneFinished = true; Log.d("cda", "Into selectRingToneTask - onPostExecute - " + selectRingtoneFinished); } } </code></pre> <hr> <p>Where I call the AsyncTask on start up:</p> <hr> <pre><code>if(srtt == null){ srtt = new SelectRingtoneTask(); Log.d("cda", "RingTone - " + srtt.getStatus()); } srtt.execute(); </code></pre> <hr> <p>The problem occur's when I start the activity and close the Activity before the AsyncTask finishes, if this happens once, it seems to be fine but after it happens a second time the AsyncTask will only ever get to the onPreExecute() method and will never complete again until the application is force stopped and restarted.</p> <p>Has anybody got any idea why this would be happening?</p>
 

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