相关疑难解决方法(0)

Android:用于获取通知的服务类中的intent.putExtra

这是我在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一起工作吗?

service android android-intent

5
推荐指数
1
解决办法
2690
查看次数

标签 统计

android ×1

android-intent ×1

service ×1