title: Displaying progress bar while intent service is running
body: <p>This seems like it should be simple, but I'm getting into a muddle. </p>
  
  <p>I start an <code>IntentService</code> from my main activity via an <code>onClick</code> event, and listen for a response from the service using a <code>PendingIntent</code> that references a static inner class <code>BroadcastReceiver</code> in the same main activity of the <code>onClick</code> event, i.e.,</p>
  
  <pre><code>public void onClick(View arg0) {
  
      Intent intent = new Intent(this, MyService.class);        
  
      PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,MyReceiver,0);
  
      startService(intent);
  
  }
  
  public static class MyReceiver extends BroadcastReceiver {
  
      public void onReceive(Context context, Intent intent) {
           // Do stuff here ....
      }
  </code></pre>
  
  <p>Now, all I want to do is show a <code>ProgressBar</code> (swirly indeterminate one) on the activity's UI whilst the <code>IntentService</code> is doing its stuff. I defined the <code>ProgressBar</code> in the xml as</p>
  
  <pre><code>&lt;ProgressBar
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          style="@android:style/Widget.Holo.ProgressBar.Large"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true"
          android:id="@+id/progress"
          android:visibility="gone"/&gt;
  </code></pre>
  
  <p>I can start it from the <code>onClick</code> event by</p>
  
  <pre><code> ProgressBar pb = (ProgressBar) findViewById(R.id.progress);
   pb.setVisibity(View.VISIBLE);
  </code></pre>
  
  <p>But I'm lost as to where and how to hide it??? I can't do it from <code>myReceiver</code> as its a static class and I don't have access to the UI. It seems so simple, but I can't figure out the best way. Any suggestions?</p>
  
  <p>Thanks!</p>