Question of displaying a ProgressDialog in a joined thread

by roland » Thu, 11 Sep 2008 18:06:56 GMT


Sponsored Links
 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.


--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by Romain Guy » Thu, 11 Sep 2008 23:50:32 GMT


 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.






-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Question of displaying a ProgressDialog in a joined thread

by roland » Fri, 12 Sep 2008 15:40:54 GMT


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






--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by Romain Guy » Sat, 13 Sep 2008 00:15:41 GMT


 es, but if you wait, you block. Don't block the UI thread :) It is
much better to have the background thread post a message to a Handler
when it's done. I suggest you to use this class to perform your
threading work:
http://code.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/UserTask.java

On Fri, Sep 12, 2008 at 12:40 AM, roland <[EMAIL PROTECTED]> wrote:



--
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by roland » Mon, 15 Sep 2008 17:56:23 GMT


 i, the reason i block the thread is that i need wait the end of the
thread before execute other methods (delete synchronized data), if i
don't use block thread's method (join or synchronized), the delete
methods will be executed before the thread. That's why i block the
thread.

I just used your class, i got the same result as not using block
method, the delete method execute before my synchronize method.

PS, your UserTask class has a good documentation.

On 12 sep, 18:15, "Romain Guy" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Froyo coming August 3rd to Evo - are you ready?

Google releases official numbers of version penetration every two weeks.

http://developer.android.com/resources/dashboard/platform-versions.html

On Wed, Aug 4, 2010 at 11:48 AM, Maps.Huge.Info (Maps API Guru) <



> 

2. Froyo coming August 3rd to Evo - are you ready?

This time it seems more official...

Same questions are still valid.

Are you ready?

-John Coryat

-- 

3. My Eclipse 3.5 always lag and have to force close - why?

4. I need Ivt_bluesoleil_6.4.314.3 activation key

5. how can we create 9-patch images.

6. Google map tiles missing with adb install

7. What is the URI for the Contacts content provider on Samsung phones? ActivityNotFoundException: