Using AlarmManager in Android, What's wrong with this?
<p>So, I'm trying to set up a simple alarm in an android program. Eventually, I want the user to be able to select a number of minutes and then receive a notification that many minutes later. Right now though, I'm just trying to set up a simple toast that goes off 5 seconds after the method is called. What am I doing wrong?</p>

<p>Here is my AlarmReceiver class</p>

<pre><code>public class AlarmReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Toast.makeText(context, "In Alarm Receiver", Toast.LENGTH_SHORT).show();
    try
    {
        Bundle bundle = intent.getExtras();
        String message = bundle.getString("alarm_message");
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    catch (Exception e)
    {
        Toast.makeText(context, "There was an error", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
    }  
}
</code></pre>

<p>And here is the method I use to set up the alarm:</p>

<pre><code>private void setAlarm()

{
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra("alarm_message", "It's been 5 seconds!");
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, pendingIntent);
    Toast.makeText(context, "Alarm Set", Toast.LENGTH_SHORT).show();
}
</code></pre>

<p>The code will get to the bottom and display my alarm set toast, but it never seems to display the toast in my AlarmReceiver class. It doesn't crash, but I get no toasts. </p>
