Reputation:
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
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
Reputation: 1247
Do it like this
task.execute();
while(task.getStatus().equals(AsyncTask.Status.RUNNING)) {
};
doWork();
Upvotes: 0
Reputation: 1604
You can override onProgressUpdate() method and check its status.
Upvotes: 2