I am making a http request
using AsyncTask
and what I want is that when I logout, the AsyncTask
should stop. so I am calling cancel(true)
in onStop()
. When I call cancel(true)
, the requests that are not started yet, are cancelled, but the problem is that isCancelled()
is never called which checks if the executing task is cancelled or not. I am checking isCancelled()
in doInBackgroud()
method of AsyncTask
Is there a way to stop the executing AsyncTask. Following is the scenario.
class AsyncClass extends AsyncTask<>{
@Override
protected String doInBackground(Void... params)
{
if(isCancelled())
{
Log.d("isCancelled", iscancelled());
}
//call the webservice
}
}
Now there is some other class from where I'm calling
if(asyncTaskObject!=null){
asyncTaskObject.cancel(true);
asyncTaskObject=null;
}
But Log statement inside iscancelled() is never called.