What is wrong with this class? My progressdialog is shown but stays at 0% then disappears, it never gets percentage updates
public class AsyncLogin extends AbstractAsync {
public AsyncLogin(Context context, AsyncCallback mAuthcallback) {
super(context, mAuthcallback);
}
@Override
protected HashMap<String, String> doInBackground(String... args) {
...
publishProgress(50);
HashMap<String, String> result = html.download();
publishProgress(75);
return result;
}
protected void onPreExecute() {
super.onPreExecute();
this.progressDialog.setMessage(this.context.getString(R.string.please_wait_logging_in));
this.progressDialog.show();
publishProgress(25);
}
protected void onProgresUpdate(Integer... progress)
{
super.onProgressUpdate(progress);
Log.v("max", "set progress" + progress[0]);
this.progressDialog.setProgress(progress[0]);
}
protected void onPostExecute(HashMap map) {
...
}
}
abstract class AbstractAsync extends AsyncTask <String, Integer, HashMap>{
protected Context context;
protected ProgressDialog progressDialog;
protected AsyncCallback mAuthcallback;
public AbstractAsync(Context context, AsyncCallback mAuthcallback) {
this.context = context;
this.mAuthcallback = mAuthcallback;
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.setProgress(0);
}
protected void onPreExecute()
{
super.onPreExecute();
progressDialog.setMessage(context.getString(R.string.loadingSomething).toString());
//dialog.show();
}
protected void onProgresUpdate(Integer... progress)
{
super.onProgressUpdate(progress);
Log.v("max", "set progress" + progress[0]);
progressDialog.setProgress(progress[0]);
}
protected void onPostExecute(HashMap result)
{
super.onPostExecute(result);
progressDialog.dismiss();
}
}
The log never writes anything
Any chance your log level is lower than verbose?
Any chance your method never reaches “publishProgress”?
Also, you are not supposed to call publishProgress in onPreExecute. The first is to be called on the backgorund thread that runs your doInBackground, the second is called by the asynctacsk mechanism before starting the bg thread.
Would you post AbstractAsync code just in case?
EDIT:
is actually to be spelled
Free Tip: use @Override annotation to make sure you are actually overriding something