【发布时间】:2010-09-08 09:19:46
【问题描述】:
我想在用户下拉通知并点击该通知时调用该活动。我该怎么做?
【问题讨论】:
我想在用户下拉通知并点击该通知时调用该活动。我该怎么做?
【问题讨论】:
在Notification 对象上调用setLatestEventInfo(),提供PendingIntent,当他们在通知抽屉中点击您的条目时将启动您的活动。这里是 a sample project 的演示。
【讨论】:
PendingIntent 时将标志传递给Intent,但看起来没有用。那么在单击通知时创建新活动之前如何关闭当前活动?
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK) 你的Intent 应该可以工作。
假设notif 是您的Notification 对象:
Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
【讨论】:
PendingIntent 时将标志传递给Intent,但看起来没有用。那么在单击通知时创建新活动之前如何关闭当前活动?
这是点击通知时调用活动的代码
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 时将标志传递给Intent,但看起来没有用。那么在单击通知时创建新活动之前如何关闭当前活动?