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, [email protected]
<[email protected]> 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.*/
> >
>

--~--~---------~--~----~------------~-------~--~----~
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