How to check if there is any background task running?

eyadMhanna

I have an activity in android that is getting data from server using AsyncTask, I'm running the task like the following:

new Task.exectue();

The problem is there are multiple calls to this AsyncTask and I want to cancel all of them when onDestroy or onBackPressed called, how can I achieve that? or as another soultion how can I check if there are any background tasks running in activity?

Kostas Drak

By Default AsyncTask executes many tasks serially. That means that when the first task finishes it starts the next one and so on. What you can do is

Global Variable:

private Task myTask;

Method:

public void accessWebService(){
   myTask = new Task().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "Param 1");
}

and then in onDestroy cancel the Task.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Check if application is running from a background task

From Dev

How to check if any activity is running?

From Dev

Async Task not running in background?

From Dev

Running a Task in the background (PCL)

From Dev

Running a capistrano task in background

From Dev

running a "background task" in javascript

From Dev

Running background task on startup

From Dev

Running a Task in the background (PCL)

From Dev

Async Task not running in background?

From Dev

Running a capistrano task in background

From Dev

How to check Microsoft Security Essential running in background?

From Dev

How to check app is running in background of foreground in BroadcastReceiver

From Dev

How to check is there any background color on canvas?

From Dev

Running an async background task in Tornado

From Dev

(iOS)Running download task in background

From Dev

How to check if previous task is still running and stop/cancel it?

From Dev

JavaScript Worker : how to check if a message was received while running expensive task

From Dev

how to check app running in foreground or background in ionic/cordova/phonegap

From Dev

How do I check if a running process is a background process?

From Dev

How do I check if a running process is a background process?

From Dev

How to check whether microphone is used by any background app

From Dev

How to get list of current running application like Task Manager except applications running in background using JAVA?

From Dev

How to check if any web browser is running, with C++ and WinAPI?

From Dev

How to execute a task in background?

From Dev

Check for any timers running in any ViewController

From Dev

Android dialog not showing when background task is running

From Dev

iOS App running background task time

From Dev

Running a background task in iOS at a specific time in the future

From Java

Android Studio: Background task running indefinitely

Related Related

  1. 1

    Check if application is running from a background task

  2. 2

    How to check if any activity is running?

  3. 3

    Async Task not running in background?

  4. 4

    Running a Task in the background (PCL)

  5. 5

    Running a capistrano task in background

  6. 6

    running a "background task" in javascript

  7. 7

    Running background task on startup

  8. 8

    Running a Task in the background (PCL)

  9. 9

    Async Task not running in background?

  10. 10

    Running a capistrano task in background

  11. 11

    How to check Microsoft Security Essential running in background?

  12. 12

    How to check app is running in background of foreground in BroadcastReceiver

  13. 13

    How to check is there any background color on canvas?

  14. 14

    Running an async background task in Tornado

  15. 15

    (iOS)Running download task in background

  16. 16

    How to check if previous task is still running and stop/cancel it?

  17. 17

    JavaScript Worker : how to check if a message was received while running expensive task

  18. 18

    how to check app running in foreground or background in ionic/cordova/phonegap

  19. 19

    How do I check if a running process is a background process?

  20. 20

    How do I check if a running process is a background process?

  21. 21

    How to check whether microphone is used by any background app

  22. 22

    How to get list of current running application like Task Manager except applications running in background using JAVA?

  23. 23

    How to check if any web browser is running, with C++ and WinAPI?

  24. 24

    How to execute a task in background?

  25. 25

    Check for any timers running in any ViewController

  26. 26

    Android dialog not showing when background task is running

  27. 27

    iOS App running background task time

  28. 28

    Running a background task in iOS at a specific time in the future

  29. 29

    Android Studio: Background task running indefinitely

HotTag

Archive