我有一个计时器,当它结束时,如果用户在后台有应用程序它发送本地通知,本地通知会将用户带到计时器Activity
,这应该触发{{ 1}}方法(适用于运行Android L的设备)我检查通过的onNewIntent()
,问题是Extras
为空。
在清单中,我已将我的活动声明为:Extras
我创建了这样的通知:
android:launchMode="singleTop"
为什么它不起作用?
修改
我在Intent notificationIntent = new Intent(getBaseContext(), CookingTimer.class);
notificationIntent.putExtra("stopTimer", true);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification noti = new Notification.Builder(this)
.setContentTitle("Il Countdown è terminato!")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(pIntent).build();
//.addAction(R.drawable.ic_launcher, "Stop", stopTimer)
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
方法内部检查
Extra
传递的notificationIntent.putExtra("stopTimer", true);
为空