I have created a simple AsyncTask and I want to cancel the same if it takes more than 3 seconds. This is what I have done after following this post :
Async Caller:
execTask = new StartParseDownload();
execTask.execute();
//new StartParseDownload(this).execute();
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
if ( execTask.getStatus() == AsyncTask.Status.RUNNING )
execTask.cancel(true);
}
}, 300 );
The task:
public class StartParseDownload extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog;
private boolean result = false;
public StartParseDownload() {
}
protected void onPreExecute(){
}
@Override
protected void onPostExecute(final Boolean success){
super.onPostExecute(success);
}
@Override
protected void onCancelled() {
Log.e("Task cancelled", "Task cancelled");
}
protected Boolean doInBackground(final String... args){
parObj.saveInBackground(new SaveCallback() {
@Override
public void done(com.parse.ParseException e){
if (e == null) {
result = true;
goIntoMainScreen();
} else {
result = false;
}
if (e != null) {
}
}
});
return false;
}
}
Where am I going wrong? Why is the onCancelled()
not getting called?