title: Can NoticationManager.notify() be called from a worker thread?
body: <p>My question is more about what is a good practice than what is possible:</p>
  
  <ul>
  <li><strong>Is it a good thing to call <code>NoticationManager.notify()</code> from a worker thread?</strong></li>
  <li><strong>Does the system execute it in the UI thread anyway or not?</strong></li>
  </ul>
  
  <p>I always try to keep in mind that stuff concerning the UI should be executed in the UI thread and the rest in worker threads, as suggested by the Android doc about <a href="http://developer.android.com/guide/components/processes-and-threads.html">Processes And Threads</a>:</p>
  
  <blockquote>
    <p>Additionally, the Andoid UI toolkit is not thread-safe. So, you must
    not manipulate your UI from a worker thread—you must do all
    manipulation to your user interface from the UI thread. Thus, there
    are simply two rules to Android's single thread model:</p>
    
    <ul>
    <li>Do not block the UI thread </li>
    <li>Do not access the Android UI toolkit from outside the UI thread</li>
    </ul>
  </blockquote>
  
  <p>HOWEVER, I was surprised by an example given by the Android doc itself (<a href="http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Progress">about showing progress in Notifications</a>), where an ongoing notification progress was updated directly from a worker thread:</p>
  
  <pre><code>mNotifyManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  mBuilder = new NotificationCompat.Builder(this);
  mBuilder.setContentTitle("Picture Download")
      .setContentText("Download in progress")
      .setSmallIcon(R.drawable.ic_notification);
  // Start a lengthy operation in a background thread
  new Thread(
      new Runnable() {
          @Override
          public void run() {
              int incr;
              // Do the "lengthy" operation 20 times
              for (incr = 0; incr &lt;= 100; incr+=5) {
                      // Sets the progress indicator to a max value, the
                      // current completion percentage, and "determinate"
                      // state
                      mBuilder.setProgress(100, incr, false);
                      // Displays the progress bar for the first time.
                      mNotifyManager.notify(0, mBuilder.build());
                          // Sleeps the thread, simulating an operation
                          // that takes time
                          try {
                              // Sleep for 5 seconds
                              Thread.sleep(5*1000);
                          } catch (InterruptedException e) {
                              Log.d(TAG, "sleep failure");
                          }
              }
              // When the loop is finished, updates the notification
              mBuilder.setContentText("Download complete")
              // Removes the progress bar
                      .setProgress(0,0,false);
              mNotifyManager.notify(ID, mBuilder.build());
          }
      }
  // Starts the thread by calling the run() method in its Runnable
  ).start();
  </code></pre>
  
  <p>That's why I'm wondering if it is actually necessary to run it on the main thread, or if the system takes care of it.</p>
  
  <p>Thanks for your help!</p>