I'm trying to handle the situation where the user loses their data connection during an Http request in an AsyncTask. Currently the AsyncTask will never finish executing if this happens and the app just stalls. I can't even check isCancelled() because the Http request just stalls out on one function call, so I can't implement a loop or anything.
I'm using the following in the UI thread but I can't figure out how to check if the task has been cancelled from within the task:
task = new LoginTask();
task.execute(this, mUsername, mPassword);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (task != null && task.getStatus() == AsyncTask.Status.RUNNING)
{
task.cancel(true);
}
}
}, 5000);