I have some work to do in the another thread (by doingAsyncTask). Work start when user click on button. But at the same time only one object of doingAsyncTask must do this work, i meen if doingAsyncTask is working, then click on button must not create a new object of doingAsyncTask and execute it, it must wait until work finish. How can i check it?
public class SearchActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//....
}
public void onclickButton(View view) {
new doingAsyncTask().execute();
}
public class doingAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... unused) {
//doing something
return(null);
}
protected void onProgressUpdate() {
}
protected void onPreExecute() {
}
protected void onPostExecute() {
}
}
}
SOLVED thx all , its works for me
if(task.getStatus() == AsyncTask.Status.FINISHED)
task=new ProgressBarShow();
if(task.getStatus() == AsyncTask.Status.PENDING){
//task=new ProgressBarShow();
task.execute();
}
Check this AsyncTask.Status
AsyncTask.Status FINISHED Indicates that onPostExecute(Result) has finished.
AsyncTask.Status PENDING Indicates that the task has not been executed yet.
AsyncTask.Status RUNNING Indicates that the task is running.
code:
if (doingAsyncTask().getStatus().equals(AsyncTask.Status.FINISHED))
doingAsyncTask().execute();
else
EDIT:
public class SearchActivity extends Activity {
doingAsyncTask asyncTask;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
asyncTask = new doingAsyncTask();
}
public void onclickButton(View view) {
if(ayncTask.getStatus().equals(AsyncTask.Status.FINISHED) || ayncTask.getStatus().equals(AsyncTask.Status.PENDING)) {
asyncTask.execute();
}
else {
// do something
}
}
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With