1

For a custom reminder app, I'm using AlarmManager and PendingIntent to set a specific time for my Notification to pop up.

I have my NotificationManager in ReceiverActivity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarm_receiver);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager)
            getSystemService(ns);
    Context context = getApplicationContext();
    CharSequence ticker = "You have notification";
    CharSequence contentTitle = "My Reminder";
    CharSequence contentText = "Reminder Content";
    Notification notification = new Notification(R.drawable.notif_icon,
            ticker, System.currentTimeMillis());
    Intent notificationIntent = new Intent(this,
            AlarmReceiverActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
        notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText,
        contentIntent);
    final int HELLO_ID = 1;
    mNotificationManager.notify(HELLO_ID, notification);
}

The ReceiverActivity pops up at the specified time plus the notification in the notification bar (upper left) and all is well. But its not so user friendly, I want only the notification to appear in the notification bar without any activities popping up when app is closed (where in realistic situations, is probably closed at the time your reminder is due)

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
  • Actually all I needed to do was to set ReceiverActivity to transparent which is possible through changing the theme in xml tho I haven't got a solution that works yet – Bruce Bilbao Oct 07 '12 at 14:48
  • Please post more code, I have a feeling you're launching the wrong thing in your AlarmManager call, but can't tell without seeing the code. – Travis Nov 19 '12 at 19:42

1 Answers1

0

Define your AlarmManager's PendingIntent to be received by a BroadcastReceiver

Intent i = new Intent(context, YourReceiver.class);
PendingIntent alarmPendingIntent= PendingIntent.getBroadcast(context, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT);

Then

public class YourReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // use a BUILDER all this is deprecated
        CharSequence ticker = "You have notification";
        CharSequence contentTitle = "My Reminder";
        CharSequence contentText = "Reminder Content";
        Notification notification = new Notification(R.drawable.notif_icon,
                ticker, System.currentTimeMillis());
        Intent notificationIntent = new Intent(this,
                AlarmReceiverActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText,
            contentIntent);
        // post notification
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager)
                context.getSystemService(ns);
        final int HELLO_ID = 1;
        mNotificationManager.notify(HELLO_ID, notification);
    }
}
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361