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. C2DM properly working on the emulator, anybody?

Hello!

I looked all over the web and in this group for a solution but I don't
seem to have any luck.
I'm probably not the only developer that needs to try C2DM on the
emulator so a solution to this could be quite useful.
First of all let me say that I'm running the latest Google APIs 8 rev
2 as AVD which should have all the necessary magic to allow me to run
C2DM (it even has all the market components to run the LVL).
I tried both Chrome to Phone and Jumpnote and it was impossible to
make the C2DM service work.
- Chrome to Phone fails when trying to connect from the Android app
running on the emulator with a "Error: Unable to connect". On the
Chrome to Phone site they recommend that Talk should be tried first
and that the Market should be available (none of these come in the
emulator image and I'm not sure if I should even try to install them
on the emulator).
- Jumpnote does not synchronize automatically and gives me an error:
"Error calling remote note sync RPC" (when I do a manual sync I can
see the docs being synchronized but looks like C2DM, which enables the
auto sync, is broken).
I also heard a comment that maybe port forwarding via adb could be
necessary (but I'm really not sure this makes any sense).

So can anybody confirm or deny that C2DM enabled apps can be run
properly on the emulator? (eg Jumpnote, Chrome to Phone). How can I
test C2DM on the emulator?
Alternatively, does anybody know of an AVD image with all features on
it? (full Market, Talk, etc)

Best!! Thx in advance.

German

-- 

2. How to try to get connection via mobile network

Hi,

I'm building an application for my own use, and I like to get
connection via mobile network but I don't know how to do that. What I
want is the same behaviour that offers severals existent widgets to
turn on/off the data connection.

Anybody can illuminate me please? Some code?? Any page with any
sample??

Thanks everybody!

Marc

-- 

3. problem with a ProgressDialog

4. Android 2.2 setResultData() issue

5. Strange error on HTC Hero running 2.1 in Turkey

6. TextColor attribute doesn't get applied to Button from a style def?

7. subscribing to SMS messages