【发布时间】:2012-08-17 06:50:33
【问题描述】:
我使用Notifications 有一段时间了,昨天我注意到PendingIntent 的文档说传递给PendingIntent.getActivity()方法的Intent 必须有FLAG_ACTIVITY_NEW_TASK 集:
请注意,活动将在 现有活动,因此您必须使用 Intent.FLAG_ACTIVITY_NEW_TASK Intent 中的启动标志。
但是,我在使用Notifications 时从未设置此标志,但到目前为止我还没有遇到任何问题。我已经看到了几个Notifications 的例子,其中FLAG_ACTIVITY_NEW_TASK 没有为PendingIntent 引用的Intent 设置。特别是,official guide 显示了下面的 sn-p:
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
如您所见,他们没有设置FLAG_ACTIVITY_NEW_TASK 标志。所以我的问题是,我应该在使用PendingIntent.getActivity() 时始终设置FLAG_ACTIVITY_NEW_TASK 标志,还是在某些情况下可以省略它?特别是在使用Notifications的时候,可以不设置这个flag就使用Intent吗?
【问题讨论】:
标签: android android-pendingintent