3.3 Implicit Intents

Intents aren’t necessarily always explicit because they don’t necessarily have to be used to call the onCreate() method of another activity of the same project. Implicit intents are used to launch other applications and processes on a user’s device that don’t belong to the same project.

Instead of naming any specific component, they declare a general action to perform and has the Android system itself take care of it. This includes the extremely common use of launching the default browser to open a link or clicking on the share icon to open any messenger app. These implicit intents are best used to enact functionality that your app itself does not contain.

In our example, we'll be creating a simple share feature. You'll notice that we create an Intent object, much like with explicit intents. We set the action of the intent, which in this case is a "send" action. There are many other options for actions, and Google provides a comprehensive list in their documentation. We also set the information to be sent and the information type.

var sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage)
sendIntent.type = "text/plain"
// Verify that there is at least one app that can receive this action
if (sendIntent.resolveActivity(packageManager) != null) {

When a ACTION_SEND request is made by the system, the phone's system will search through all applications on the device and open up a list of ones that are capable of receiving this action (e.g., Gmail, Messenger, Google Drive can all receive ACTION_SEND intents) and the user can select one of the choices.

Intents give us a lot more functionality to create a positive experience for our user. Not only can we create and switch between multiple screens with explicit intents, but we can allow our user to easily navigate to specific applications with pre-filled data from the intent extras (like opening Google Maps with specific coordinates already filled in).

Last updated