Call activity when on notification tap event
Assuming that notif
is your Notification
object:
Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
Here is the code to call activity when notification is clicked
Notification notif = new Notification(R.drawable.ic_launcher,"List of Contacts...", System.currentTimeMillis());
Intent notificationIntent = new Intent(context,AllContacts.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
Call setLatestEventInfo()
on the Notification
object, supplying a PendingIntent
that will start your activity when they tap on your entry in the notification drawer. Here is a sample project demonstrating this.