lannyf
lannyf

Reputation: 11025

android, what would be the use case for one Pendingintent to launch multiple activities?

public static PendingIntent getActivities (Context context, 
                int requestCode, 
                Intent[] intents, 
                int flags)

In the doc , it says the intent[] is "Array of Intents of the activities to be launched."

It seems to be used for the case of launching multiple activities.

Could not think of a use case that multiple activities to be opened through a notification tap. Anyone has a sample for showing to launch multiple activities through one Pendingintent?

Upvotes: 1

Views: 414

Answers (1)

David Wasser
David Wasser

Reputation: 95578

The documentation for startActivities() (which is what this eventually ends up doing) explains what happens pretty clearly:

Launch multiple new activities. This is generally the same as calling startActivity(android.content.Intent) for the first Intent in the array, that activity during its creation calling startActivity(android.content.Intent) for the second entry, etc. Note that unlike that approach, generally none of the activities except the last in the array will be created at this point, but rather will be created when the user first visits them (due to pressing back from the activity on top).

So you would use this if you want to launch a specific Activity in an app and you want to make sure that the activity stack is set up appropriately, so that when the user presses BACK, it would cycle back through the stack of activities that you set up.

Personally, I understand what they were trying to do here, but I think it is a major fail and there are better ways of doing this (basically having your app be smart enough to understand how to get you back to the previous Activity without assuming that it is present in the stack). But that's just my un-asked-for opinion.

Upvotes: 1

Related Questions