Make use of Handlers to tell the main thread when the other thread has  
stopped or completed its task.

final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
                //do something here. Will be done on main thread
        }
};

Use it in your thread like this

handler.sendMessage(message);




On 25-Mar-09, at 12:01 PM, guishenl...@gmail.com wrote:

>
> I still have some question on it. If I put the backgroundWork() in
> another thread, how can the main UI thread know background thread has
> finished? And how to pause the main UI thread to wait for
> backgroundWork().
>
> On Mar 25, 12:44 pm, Marco Nelissen <marc...@android.com> wrote:
>> The problem is that your 'backgroundWork()" method is not actually
>> running in the background, but in the main UI thread. You'll need to
>> do the work in a separate thread.
>>
>> On Tue, Mar 24, 2009 at 8:02 PM, guishenl...@gmail.com
>>
>>
>>
>> <guishenl...@gmail.com> wrote:
>>
>>> I want to show a ProgressBar while doing some background operation,
>>> but my code seems not to work. I hope someone can help me to solve
>>> this problem. Thank you in advance!Here is my code and explanation :
>>
>>>  public boolean onMenuItemSelected(int featureId, MenuItem item) {
>>>        switch(item.getItemId()) {
>>>        case CASEONE_ID:
>>>                ProgressBar progress = (ProgressBar)findViewById
>>> (R.id.ProgressBar);
>>>        progress.setVisibility(View.VISIBLE);
>>>         progress.bringToFront();
>>>        progress.invalidate();
>>
>>>                 backgroundWork();
>>
>>>                 progress.setVisibility(View.GONE);
>>>        progress.invalidate();
>>>                return true;
>>>              }
>>>        return super.onMenuItemSelected(featureId, item);
>>>    }/*In fact I never see the progressbar by this code, instead the
>>> program will keep frozen until backgroundWork() finish. But what I
>>> want is the progressbar can appear in the screen while  
>>> backgroungWork
>>> () is being processed.
>>
>>> private void backgroundWork(){
>>>              for(int i=0;i<1E8;i++);
>>> }/*This is not the exact work I did in my own program. I change it  
>>> to
>>> this form is just to tell you my operation will occupy the processor
>>> for long time.*/- Hide quoted text -
>>
>> - Show quoted text -
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to