I think using an AsyncTask is better. On one hand, it's just simpler
to implement. On the other hand, it's built in Android and you can be
100% it's supported and the way Android was designed to work. So,
rather than using a handler and multiple threads, I find it simpler to
display the loading dialog in the onCreate() method, do all the work
in the doInBackground() method of the AsyncTask extending class and
dismiss the dialog in the onPostExecute(). I don't know about you, but
I find it a lot nicer.

On Sep 23, 7:01 pm, Beanie <[email protected]> wrote:
> 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