Displaying a Delayed Toast from a BroadcastReceiver
<p>I'm trying to display a message to the user some time after an event is received by a BroadcastReceiver.</p>

<pre><code>public class MyReceiver extends BroadcastReceiver {

  private Timer timer = new Timer();

  @Override
  public void onReceive(Context context, Intent intent) {
      // Display message in 10 sec.
      timer.schedule(new MessageTask(context, "Test Message"), 10 * 1000);
  }

  private static class MessageTask extends TimerTask {
    public MessageTask(Context context, String message) {
      this.context = context;
      this.message = message;
    }

    public void run() {
      Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
  }
}
</code></pre>

<p>When I run this I get the following exception:</p>

<pre><code>java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
</code></pre>

<p>Is this the right way to do something like this?  Should I be using something other then a Timer?  And what is the right way to get a Context object in this situation?</p>

<p>Thank you</p>
