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)