我已经使用Notifications 一段时间了,昨天我注意到文档PendingIntent说传递给PendingIntent.getActivity()方法的 Intent 必须具有FLAG_ACTIVITY_NEW_TASK集合:
请注意,该活动将在现有活动的上下文之外启动,因此您必须在 Intent 中使用 Intent.FLAG_ACTIVITY_NEW_TASK 启动标志。
但是,我在使用 s 时从未设置过这个标志Notification,但到目前为止我还没有遇到任何问题。我已经看到了几个Notifications 的示例,其中FLAG_ACTIVITY_NEW_TASK没有为 the引用的Intentthe设置。PendingIntent特别是,官方指南显示了以下片段:
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标志。所以我的问题是,我应该FLAG_ACTIVITY_NEW_TASK在使用时始终设置标志PendingIntent.getActivity(),还是在某些情况下可以省略它?特别是在使用Notifications 时,我可以在不设置此标志的情况下使用 Intent 吗?