I have an AsyncTask where I invoke a method that download some data from internet and performs certain operations.
In the emulator this works always despite the connection speed but on real devices if connection or device isn't fast this task is automatically terminated. I don't know why, but probably there is some kind of default timeout in Android default task management.
How could I fix this problem?
How to force the completion of the task always?
Here my code
myTask = new AsyncTask<Void, Void, Void>() {
ProgressDialog pd;
boolean correctlyInitialized = true;
@Override
protected void onPreExecute() {
pd= new ProgressDialog(CatcherTree.this);
pd.setCancelable(false);
try {
pd.show();
} catch (Error e) {
e.printStackTrace();
}
}
@Override
protected Void doInBackground(Void... params) {
long t = System.currentTimeMillis();
//this method requires time to complete
updateAllDataSet(CatcherTree.this);
return null;
}
@Override
protected void onPostExecute(Void rate) {
pd.dismiss();
}
}.execute();
Aucun commentaire:
Enregistrer un commentaire