Arc*_*pgc 5 service android android-intent
这是我在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);
}
Run Code Online (Sandbox Code Playgroud)
所以点击后通知从状态栏,我将结束myActivity.
问题是这些行总是在myActivity中给出错误.
this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")
Run Code Online (Sandbox Code Playgroud)
putExtra()不能与PendingIntent一起工作吗?
请尝试使用此代码:
String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2690 次 |
| 最近记录: |