Just check isCancelled()
once in a while:
protected Object doInBackground(Object... x) {
while (/* condition */) {
// work...
if (isCancelled()) break;
}
return null;
}
More Related Contents:
- Code not working in onPostExecute function
- NetworkOnMainThreadException [duplicate]
- Running multiple AsyncTasks at the same time — not possible?
- What arguments are passed into AsyncTask?
- Warning: This AsyncTask class should be static or leaks might occur
- How to display Toast in Android?
- Asynctask vs Thread in android
- Android AsyncTask example and explanation [duplicate]
- Android Fragments. Retaining an AsyncTask during screen rotation or configuration change
- Android AsyncTask for long running operations
- AsyncTask threads never die
- getting context in AsyncTask
- ProgressDialog not shown when AsyncTask.get() called [duplicate]
- Example: Android bi-directional network socket using AsyncTask
- Android calling AsyncTask right after an another finished
- OkHttp Library – NetworkOnMainThreadException on simple post
- Executing Multiple AsyncTask’s Parallely
- How to use asynctask to display a progress bar that counts down?
- Picasso loading of image spawned inside AsyncTask
- Properly Using AsyncTask get()
- Android: How to return async JSONObject from method using Volley?
- Webview with asynctask on Android
- running parallel AsyncTask
- Stop AsyncTask doInBackground method
- How to pass variables in and out of AsyncTasks?
- Android speech recognizing and audio recording in the same time
- how to stop ASyncTask thread in android
- How to display a Toast in Android AsyncTask?
- Need Help in Downloading in Background Images in Android?
- How to execute background task when Android app is closed / set to background?