Intents and Intent Filters (Part 2)
Learn about intents to start an activity.
We'll cover the following...
In Android, intents allow various app components to communicate with each other and interact with other apps. Apps use intents to start activities, broadcast messages to other apps, and access data from different sources. Let’s explore intents to start an activity.
Intent starting an activity
The following figure shows how an intent can start an activity. The Android OS starts the app component when the intent explicitly uses the name to start an activity.
In the figure above, Activity A wants to start Activity B. This process works as follows:
- Activity A calls the - startActivity()method, passing it the- Intentas a parameter, and this method sends the- Intentto the Android OS.
- The Android OS receives the - Intentand looks up the activity that corresponds to the specified class. It also checks the- Intentagainst the activity’s intent filter to make sure that the activity is capable of handling the- Intent.
- If there’s only one activity that can handle the - Intent, the Android OS starts the activity by invoking its- onCreate()method and passes the- Intentobject to it. Activity B is then displayed on the screen.
- If there are multiple activities that can handle the - Intent, the user is presented with a dialog that lists the available activities. The user can then choose which activity to launch.
- Once Activity B starts, it can retrieve any additional data from the - Intent...