Display a progress dialog while computing

1 vote · 3 comments

This snippet creates a ProgressDialog and a thread to execute something with an unknown duration (web service as an example). When this "thing" finishes, a message is sent to the parent of the thread to stop the ProgessDialog.

raw ·
copy
· download
final ProgressDialog dialog = ProgressDialog.show(this, "Title", "Message", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); } }; Thread checkUpdate = new Thread() { public void run() { // // YOUR LONG CALCULATION (OR OTHER) GOES HERE // handler.sendEmptyMessage(0); } }; checkUpdate.start();
Add a comment

3 Comments

Why it's 10? I thought it should be 9.8, which is gravity value.

Reply · Sept. 12, 2009, 4:38 a.m.

Sorry, wrong post......

Reply · Sept. 12, 2009, 4:41 a.m.

You can just use AsyncTask then show ProgressDialog on onPreExecute method then dismiss it on onPostExecute.

Reply · Sept. 12, 2009, 8:52 a.m.