Back button only dismissing Progress Dialog and not the AsyncTask
I am trying to cancel my aynctask when the user hits the back button. I
have done my research on which methods to use for this operation and I
found it difficult to figure out why are there more than one method. I
have found one method and tried it but it only dismisses my ProgressDialog
and my aynctassk still executes. So can somebody assist me with this issue
of getting my asynctask to dismiss the proper way.
@Override
public void onBackPressed()
{
/** If user Pressed BackButton While Running Asynctask
this will close the ASynctask.
*/
if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED)
{
mTask.cancel(true);
}
super.onBackPressed();
finish();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
/** If Activity is Destroyed While Running Asynctask
this will close the ASynctask. */
if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED)
{
mTask.cancel(true);
}
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
if (pDialog != null)
{
if(pDialog.isShowing())
{
pDialog.dismiss();
}
super.onPause();
}
}
And please let me know If I need to post my doInBackGround method to the
question
No comments:
Post a Comment