Do I need to use FLAG_ACTIVITY_NEW_TASK in a PendingIntent notification?

I used it Notificationfor a while, and yesterday I noticed that the documentation PendingIntentsays that the intent that is being passed PendingIntent.getActivity()must have a parameter FLAG_ACTIVITY_NEW_TASK:

Note that the action will be launched outside the context of the existing activity, so you should use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the intent.

However, I never set this flag when using Notifications, and so far I have not experienced any problems. I saw several examples Notificationwhere it is FLAG_ACTIVITY_NEW_TASKnot set to Intentthe one referenced PendingIntent. In particular, the official guide shows the snippet below:

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(), , ? , Notification s, Intent ?

+5
2

, . .

+1

, FLAG_ACTIVITY_NEW_TASK. .

(25 2017 ) , :

// Creates an Intent for the Activity
Intent notifyIntent =
        new Intent(this, ResultActivity.class);
// Sets the Activity to start in a new, empty task
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Creates the PendingIntent
PendingIntent notifyPendingIntent =
        PendingIntent.getActivity(
        this,
        0,
        notifyIntent,
        PendingIntent.FLAG_UPDATE_CURRENT
);
0

All Articles