Reputation: 1
I want to show a ProgressDialog when running a time consuming method using a private class which extends AsyncTask in an activity class. But the ProgressDialog which is supposed to be appear in onPreExecute doesn't show up when onPreExecute. Instead of it, the ProgressDialog shows up and dismiss immediately after the time consuming method is done.
public class ABC extends Activity {
/*somewhere in ABC
load = new Load();
load.execute(a,b,c);
int action = load.get();*/
private class Load extends AsyncTask<Object, Integer, Integer>{
private ProgressDialog progDailog;
@Override
protected Integer doInBackground(Object... param) {
Log.v("!!!!!!Load!!!!!!!!!","doInBackground");
Object a = (Object) param[0];
int b = (Integer) param[1];
int c = (Integer) param[2];
return a.doSomething(b, c);
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
progDailog.dismiss();
Log.v("!!!!!!Load!!!!!!!!!","onPostExecute");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.v("!!!!!!Load!!!!!!!!!","onPreExecute");
progDailog = new ProgressDialog(ABC.this);
progDailog.setMessage("Loading...");
progDailog.show();
}
}
}
Below is the logcat:
05-03 00:38:49.202: V/!!!!!!Load!!!!!!!!!(14666): preExecute
05-03 00:38:49.202: D/ProgressBar(14666): setProgress = 0
05-03 00:38:49.202: D/ProgressBar(14666): setProgress = 0, fromUser = false
05-03 00:38:49.202: D/ProgressBar(14666): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000
05-03 00:38:49.232: V/!!!!!!Load!!!!!!!!!(14666): doInBackground
05-03 00:38:53.662: I/Choreographer(14666): Skipped 269 frames! The application may be doing too much work on its main thread.
05-03 00:38:53.762: D/ProgressBar(14666): updateDrawableBounds: left = 0
05-03 00:38:53.762: D/ProgressBar(14666): updateDrawableBounds: top = 0
05-03 00:38:53.762: D/ProgressBar(14666): updateDrawableBounds: right = 144
05-03 00:38:53.762: D/ProgressBar(14666): updateDrawableBounds: bottom = 144
05-03 00:38:53.772: V/!!!!!!Load!!!!!!!!!(14666): onPostExecute
Upvotes: 0
Views: 958
Reputation: 5068
It depends upon the definition of doSomeThing
method. Since the execution time for this method or the operation you are performing is very short. thats why it is disappearing instantly. But if you want to see dialog or conform is it working properly. you can sleep in doInBackground
method.paste this code in your doInBackground
method
try{
Thread.sleep(3000);
}
catch(Exception e){
e.printStackTrace();
}
now you will see dialog for three seconds.
Upvotes: 1