Skip to content Skip to sidebar Skip to footer

Why Use Start Activities?

I've been looking through the API documentation, and noticed starting with API level 16 the Context class includes the following method: public abstract void startActivities (Inten

Solution 1:

It's rarely used in application code. I was going to say never, but I'm not that sure ;)

However, it can be used to create a synthetic back stack, when starting a new Task. You want to have a ready-made back stack, so that the back key navigates "hierarchically" inside this task.

Curiously, it's better explained in the documentation of ContextCompat than in Context itself.

Start a set of activities as a synthesized task stack, if able.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

startActivities provides a mechanism for constructing a synthetic task stack of multiple activities. If the underlying API is not available on the system this method will return false.

Solution 2:

Never used it myself, but I think it is useful when you want to recreate your activity stack, when starting a new fresh task. For example when your application gets launched from a notification, the system won't use an existing task for your application but instead create a new task with your application on it by default. In this case you may want to start on a certain position of your activity stack, and with this method you could start all your activities with one call

Solution 3:

I have used the method. In some specific sutiation, I clear the task stack when I create a new activity .But when I back to the activity which was already cleared in the task stack, I used the startActivities() to create a aritificial task stack.

Post a Comment for "Why Use Start Activities?"