Well,

The approach I follow is this:

Of-course, what you have observed is right. You are blocking the UI
thread. And, calling dismiss, after show, will obviously dismiss the
dialog, instantly.

So, Whenever you need to show a progress dialog, call show method from
the UI Thread, and then start another thread, where you do your work.
>From within that thread, you need to call a handler, which then
dismissed the dialog.

Something like this.

Your Activity should implement Runnable.

pDialog.setMessage("Your Message");
        pDialog.show();

Thread workerThread = new Thread(this);
workerThread.start();



Now in your run method, do whatever you want, but after you finish,
call the handler...

public void run(){
//do work...

handler.sendEmptyMessage(0);
}

private Handler handler = new Handler(){
        public void handleMessage(int what){
                 pDialog.dismiss();
         }
};
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to