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.
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();
3 Comments
Why it's 10? I thought it should be 9.8, which is gravity value.
Sorry, wrong post......
You can just use AsyncTask then show ProgressDialog on onPreExecute method then dismiss it on onPostExecute.