Is it possible to stop asynctask from another activity or fragment?

351
February 13, 2017, at 5:31 PM

I want to close or kill asynctask which is running in background. I am using a navigation bar. Using asynctask.cancel is not working .I am passing asynctask object through main activity to navigation drawer adapter. but its not working. My question is how to stop asynctask from another activity? or how to kill asynctask anywhere?

Answer 1

Try using task.cancel(true);

The documentation of AsyncTask provides some additional details in the 'Cancelling a task' section:

A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)

Rent Charter Buses Company
READ ALSO
Automatic bill generator

Automatic bill generator

I want to create an mobile application that has a reader to scan small stickers with numbers and name on itThe scanner is connected to the phone and the user scans the sticker for any number of items and the bill is generated

428
How to add list in HR as expandable Listview

How to add list in HR as expandable Listview

I am trying to implement expandable listview and I know that I can do it by using adapter of expandable listviewBut i am not getting a proper way to bind the data among

359
Is it true that OpenCV can only do real time image processing on Android Studio?

Is it true that OpenCV can only do real time image processing on Android Studio?

I am new to OpenCV and Android studioI would like to know if Opencv can do post processing on images, instead of only real time image processing in the camera view

419
Xamarin Android release compile error

Xamarin Android release compile error

I've tested every solution proposed for my problemIn particular, my app build correctly in Android debug mode, not in release mode

660