这是我在服务类中的showNotification方法:
private void showNotification() {
Notification notification = new Notification(R.drawable.icon,
"New Notification", System.currentTimeMillis());
Intent i = new Intent(this, myActivity.class);
i.putExtra("notification", "MyNotif");
i.putExtra("notifiedby", "NotedBy");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, "NotedBy", "MyNotif", contentIntent);
nm.notify(111, notification);
}
所以点击状态栏中的通知后,我将以 myActivity 结束。
问题是这些行总是在myActivity中提供 false 。
this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")
putExtra()不能与PendingIntent一起使用吗?
答案 0 :(得分:6)
请尝试使用此代码:
String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");