I have an activity consisting of AsyncTask aimed at launching a request when a user clicks a button. I was looking for answers, but I did not find the same problem, or it is not the same for me. The code does what I want, but the ProgressDialog looks locked because the counter does not rotate sometimes (almost all the time).
When I click the button:
AsyncTask is launched β showDialog () is called onPreExecute β startSearch (SearchManager starts a new AsyncTask, and a heavy call to the network occurs in doInBackground) β doInBackground in Activity is waiting for SearchManager β to load.
Code for the button:
button_search.setOnClickListener(new OnClickListener() { public void onClick(View v) { new SearchTask().execute(); } });
Code for AsyncTask in search operation:
private class SearchTask extends AsyncTask<Void,Void,Void>{ @Override protected void onPreExecute(){ showDialog(DIALOG_LOADING_ID); searchManager.startSearch(); } @Override protected Void doInBackground(Void... params) { while(searchManager.isLoading()){ try {Thread.sleep(150);} catch(Exception e){}; } return null; } @Override protected void onPostExecute(Void ret){ try {dismissDialog(DIALOG_LOADING_ID);} catch (Exception e){}; if ( searchManager.errorOccurred() ){
Code for SearchManagerAsyncTask: which runs directly through startSearch
protected class SearchAsync extends AsyncTask <Void,Void,Void>{ @Override protected Void doInBackground(ComSearchAds... datas) { global.getDataManager().doSearch();
I, apparently, am doing something wrong, but I canβt find what and how to avoid it. Thank you for your help!
DECISION:
Finally, it seems that the non-rotating ProgressDialog was because I used the same instance of the ProgressDialog and
showDialog(DIALOG_LOADING_ID);
used with a problem of reasons i changed to
removeDialog(DIALOG_LOADING_ID)
and now it works fine.
Thanks to everyone, and I hope that someday he will be able to help someone!