Answer the question
In order to leave comments, you need to log in
How to continue execution of a stopped AsycnTask in Android?
I work with AsyncTask and it became necessary to pause the download (the download is not real, everything is normal for the sake of the example), there are start, stop, resume buttons. When you click on start, the execute() method is called; , and when clicking on stop, the cancel(false); which makes isCancelled() from false to true and this code:
if (isCancelled()) {
Toast.makeText(MainActivity.this, "The load stopped!", Toast.LENGTH_SHORT).show();
return null;
}
case R.id.b_resume :
if (myAsyncTaskDemo.isCancelled()) {
// resume
}
Answer the question
In order to leave comments, you need to log in
You can't use asynctasks this way.
1) A canceled task cannot be resumed
2) By default, they are executed sequentially, so even if you can do such a trick, it will stop the rest of the tasks in the application
3) You have a memory leak. Doing so is not recommended.
Take a better real example, and don't fool around. Nobody uses asynctasks for downloads that can be paused (i.e. long enough). There are other APIs for this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question