5

这是我在Service 类中的 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 中总是给出错误。

this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")

putExtra() 不能与 PendingIntent 一起使用吗?

4

1 回答 1

6

试试这个代码:

String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");
于 2012-10-10T13:56:08.537 回答