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. Refunds in the Market

I want to offer my users the option to install a different deployment for 
free but because I can't make a free version and switch it to a paid 
version, I want to offer them a refund if they install the new product. I 
will refund people who bought the app previously.

Has anyone used the refund option in the market to refund money to their 
customers?
I want to refund the customers but *not* remove the application from their 
phones.

Essentially I want to give credit to users who already bought the original 
app.

- Brill Pappin

-- 

2. How to link 3rd party .so file in android

Hi,

Can someone let me know how to do this?
I have a third party .so file that has to be used in my android
application.
I have written the jni and tried to access the apis of the third party
library.
But am getting errors that library not found.

Can some one help on this?

-- 

3. When is an app movable to sd card?

4. how to fetch the facebook friend list

5. How to give path..?

6. Nexus S with soju-userdebug 2.3 GRH55 79397 test-keys / will not update to 2.3.1 GRH78

7. How can we give path..?