当通知点击事件时致电活动
致电setLatestEventInfo()
对Notification
对象,提供一个PendingIntent
,当他们点击通知抽屉中的条目时将开始您的活动。演示这个是a sample project。
假设notif
是你Notification
对象:
Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
我可以在点击通知栏上的通知时开始活动。但看起来它创建新的活动,虽然目前的活动正在运行。我试图在调用PendingIntent时将Flag传入'Intent',但看起来没有工作。那么在点击通知时如何关闭当前活动才能创建新活动? – 2015-04-03 02:00:03
下面是代码调用活动通知被点击
Notification notif = new Notification(R.drawable.ic_launcher,"List of Contacts...", System.currentTimeMillis());
Intent notificationIntent = new Intent(context,AllContacts.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
我可以在点击通知栏上的通知时开始活动。但看起来它创建新的活动,虽然目前的活动正在运行。我试图在调用PendingIntent时将Flag传入'Intent',但看起来没有工作。那么在点击通知时如何关闭当前活动才能创建新活动? – 2015-04-03 02:00:08
当点击通知栏上的通知时,我可以开始活动。但看起来它创建新的活动,虽然目前的活动正在运行。我试图在调用PendingIntent时将Flag传入'Intent',但看起来没有工作。那么在点击通知时如何关闭当前活动才能创建新活动? – 2015-04-03 01:59:18
@HuyTower:''Intent''上的'setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)'应该可以工作。 – CommonsWare 2015-04-03 10:37:57
@CommonsWare:完美适合我! – 2017-11-17 11:12:17