Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (Intent[] intents)

I've been Googling around in attempts to stave my curiosity through an example of it's use in application code, a question, or article, but I haven't come across anything as of yet. If someone has already asked a similar question, please let me know.

Anyways, I'm curious as to when this should/could be used in application code, and what (if any) benefits of doing so would be? I've personally never seen this method used, and I fail to grasp it's utility. Any feedback will be appreciated.

like image 988
Submersed Avatar asked Jun 18 '14 22:06

Submersed


People also ask

What is start activity?

Starting activities or services. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.

What does start activity for result do?

By the help of android startActivityForResult() method, we can get result from another activity. By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa.

Where do you define the starting activity of your application?

Specify Your App's Launcher Activity This is the activity that serves as the main entry point to your app's user interface. You can define which activity to use as the main activity in the Android manifest file, AndroidManifest. xml , which is at the root of your project directory.


2 Answers

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.

like image 113
matiash Avatar answered Oct 28 '22 03:10

matiash


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

like image 36
Julian Suarez Avatar answered Oct 28 '22 02:10

Julian Suarez