In my application I use an AsyncTask on start up of my Activity to fetch the ringtone of a particular contact.
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.
Here is my code:
The AsyncTask itself:
private class SelectRingtoneTask extends AsyncTask<String, Void, Void> {
// 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);
}
}
Where I call the AsyncTask on start up:
if(srtt == null){
srtt = new SelectRingtoneTask();
Log.d("cda", "RingTone - " + srtt.getStatus());
}
srtt.execute();
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.
Has anybody got any idea why this would be happening?