user7315434
user7315434

Reputation:

Get AsyncTask class status android

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...

Upvotes: 0

Views: 240

Answers (3)

Pranav Darji
Pranav Darji

Reputation: 752

    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

Upvotes: 1

Sunil Chaudhary
Sunil Chaudhary

Reputation: 1247

Do it like this

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

};
doWork();

check this

Upvotes: 0

SANJAY GUPTA
SANJAY GUPTA

Reputation: 1604

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

Upvotes: 2

Related Questions