I\'ve an AsyncTask and I want it to stip execution when back button is pressed. I also want the app to return to the previous displayed Activity. It seems I\'ve managed in stop
In your activity, override Back Button, stop the AsyncTask in it, and call finish for current activity.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
MyTask.cancel();
IscrizioniActivity.this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}