Thursday, February 24, 2011

progress dialog while computing

By Magesh Kumar   Posted at  3:54 AM   Android No 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. 
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();

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.