Intents and Intent Filters (Part 2)
Learn about intents to start an activity.
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 theIntent
as a parameter, and this method sends theIntent
to the Android OS.The Android OS receives the
Intent
and looks up the activity that corresponds to the specified class. It also checks theIntent
against the activity’s intent filter to make sure that the activity is capable of handling theIntent
.If there’s only one activity that can handle the
Intent
, the Android OS starts the activity by invoking itsonCreate()
method and passes theIntent
object 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 ...