Cancel Asynctask When User Presses Back Button
I have an AsyncTask in which I show a ProgressDialog in the onPreExecute, and hide it again in onPostExecute, something like final class UploadTask extends AsyncTask { ProgressD
Solution 1:
I haven't tested this, but try something like this:
finalclassUploadTaskextendsAsyncTaskimplementsOnDismissListener{
ProgressDialogdialog=newProgressDialog(...);
protectedonPreExecute() {
dialog.setOnDismissListener(this);
dialog.show();
}
protectedonPostExecute() {
dialog.hide();
}
@OverridepublicvoidonDismiss(DialogInterface dialog) {
this.cancel(true);
}
};
Solution 2:
I think you are looking for this: onCancelled()
http://developer.android.com/reference/android/os/AsyncTask.html
Post a Comment for "Cancel Asynctask When User Presses Back Button"