I am reading a tutorial on pending intent and how it is used with notification manager.
In that page, the following code is mentioned :
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.addAction(R.drawable.icon, "Call", pIntent)
.addAction(R.drawable.icon, "More", pIntent)
.addAction(R.drawable.icon, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
I want to ask why the notification manager needs to be provided a pending intent (why does it need my app's identity to send an intent) ?
Why can't it be just given an intent ?
Edit : Please don't answer with the definition of pending intent. I know what a pending intent is. What I am interested in finding is why can't the notification just use a normal intent with some API like startActivity().