Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Know if AsyncTask is Running

I have an activity which gets called every time a Call is ended. This activity has below AsyncTask.

UploadRecordings uploadRecordings = new UploadRecordings();
uploadRecordings.execute(context);

Now when I get many Calls one after another, everytime new AysncTask is created. But Android limits the number of AsyncTask to 5. So problem is I want to check if a AsyncTask is already running, and if found running, don't create a new AsyncTask. I want to create a new AsyncTask if there is no AsyncTask running.

Any Help be Appreciated.

like image 452
Mehul Kanzariya Avatar asked Dec 04 '22 22:12

Mehul Kanzariya


1 Answers

Use getStatus() to get the status of your AsyncTask. If status is AsyncTask.Status.RUNNING then your task is running.

check this way

if(uploadRecordings.getStatus() == AsyncTask.Status.RUNNING){
    // My AsyncTask is currently doing work in doInBackground()
}

For More Detail Read : Android, AsyncTask, check status?

like image 176
Harshad Pansuriya Avatar answered Dec 06 '22 12:12

Harshad Pansuriya