Thanks for response, is there some other ways to wait the end of a
thread?



On 11 sep, 17:50, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> By calling join() on the UI thread, you are blocking the UI thread.
> It's as if you were not using a background thread. That's why the
> ProgressDialog cannot be displayed.
>
>
>
> On Thu, Sep 11, 2008 at 3:06 AM, roland <[EMAIL PROTECTED]> wrote:
>
> > Hello, i have a question of displaying a ProgressDialog by joining the
> > threads. In my application, i will synchronize data with the server,
> > and remove the synchronized data from database. The synchronization
> > takes long time, so i decide to display a progressdialog during this
> > process. Of course i use a new thread to deal the synchronization,
> > here is what i use for the first time:
>
> > syncProgressDialog = ProgressDialog.show(Function.getContext(),
> > "Please wait...", "Synchronizing application's data...", true, false);
>
> > new Thread(new Runnable() {
> >        public void run() {
> >                synchronize();
> >                syncProgressDialog.dismiss();
> >        }
> > }).start();
>
> > removeData();
>
> > The problem i met with this solution is the main thread didn't launch
> > this thread immediately, it called the removeData before the new
> > Thread. Apparently the main thread don't wait the new Thread finishes
> > before execute the following method. So i changed this solution to :
>
> > syncProgressDialog = ProgressDialog.show(Function.getContext(),
> > "Please wait...", "Synchronizing application's data...", true, false);
>
> > Thread thread = new Thread(new Runnable() {
> >        public void run() {
> >                synchronize();
> >                syncProgressDialog.dismiss();
> >        }
> > });
> > thread.start();
> > try {
> >        thread.join();
> > }
> > catch (InterruptedException e) {
> >        e.printStackTrace();
> > }
>
> > removeData();
>
> > I used the join method to wait the end of synchronize thread before
> > removeData, there is another problem comes, the ProgressDialog didn't
> > display on the screen. I tried use handler:
>
> > Thread thread = new Thread(new Runnable() {
> >        public void run() {
> >                synchronize();
> >                handler.post(new Runnable() {
> >                        public void run() {
> >                                removeDialog();
> >                        }
> >                });
> >        }
> > });
>
> > private void removeDialog() {
> >        syncProgressDialog.dismiss();
> > }
>
> > Nothing changed, could anyone show me a sample code to display the
> > ProgressDialog in a joined thread or tell me which part i didn't
> > implemented correctly.
>
> --
> Romain Guywww.curious-creature.org
--~--~---------~--~----~------------~-------~--~----~
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