Please see retryableasynctask and see if this helps.
Using:
new RetryableAsyncTask<Params, Progress, Result>(myActivity) {
@Override
protected void onPreExecute() {
}
@Override
protected Result doInBackground(Params... params) {
return MyExpensiveTask.get(params);
}
@Override
protected void onPostExecute(Result result) {
}
}.execute(myParams);
Overriding onError Behavior
By default, the onError method shows the Cancel and Redo button options. However, you may want to do something else when something goes wrong. To do this, override onError using native error handling.
new RetryableAsyncTask<Params, Progress, Result>(myActivity) {
@Override
protected void onError(Throwable error, final Params... params) {
}
}.execute(myParams);
source
share