I have 2 activities in my app and I would like activity X to popup a notification – once its clicked activity Y will open and read params from the notification.
So I’ve written this:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
CharSequence tickerText = NOTIFY_TICKER_NAME;
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, PopTask.class);
notificationIntent.putExtra("task", "http://www.google.com");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);
Problem is, when I try to read the extras – i get null.
What can I do?
Thanks
oshafran,
In order for
putExtra()to work in this case you also have to usesetAction(). I’m not entirely sure why this is the case…seems to be some quirk. The value passed insetAction()can be anything.Try: