0

I am using a async class to do a task,I need to get the status of the asynctask...

new Asyncimg().execute();
if(AsyncTask.Status==AsyncTask.Status.RUNNING)

This shows an error. How can i resolve this issue...

3 Answers3

2

You can override onProgressUpdate() method and check its status.

SANJAY GUPTA
  • 1,564
  • 13
  • 21
1
    First thing is declare your AsyncTask Class globe like 

    private AsyncTaskUserLike asyncTaskUserLike;

    then check the status of your asynctask 

    if (asyncTaskUserLike != null && asyncTaskUserLike.getStatus() == AsyncTask.Status.PENDING) {
                asyncTaskUserLike.execute();
            } else if (asyncTaskUserLike == null || asyncTaskUserLike.getStatus() == AsyncTask.Status.FINISHED) {
                asyncTaskUserLike = new AsyncTaskUserLike();
                asyncTaskUserLike.execute();
            }

Same as above you can check for running status like,

asyncTaskUserLike.getStatus() == AsyncTask.Status.RUNNING
Pranav Darji
  • 744
  • 3
  • 13
0

Do it like this

task.execute();
while(task.getStatus().equals(AsyncTask.Status.RUNNING)) {

};
doWork();

check this

Alfergon
  • 5,463
  • 6
  • 36
  • 56
Sunil Chaudhary
  • 1,221
  • 12
  • 25