Using Implicit Intents

The explicit Intent approach works fine when the activity to be started is one of yours. If you are going to start an activity from some other app, such as a Web browser to view a URL, an explicit Intent will be a problem. After all, you have no idea what Web browser will handle the request (Chrome? Firefox? Brave? Dolphin? something else?). Plus, you did not write the Web browser and do not know what classes are in it. And, even if you used tools to peek inside the other app and find out its class structure, the developers of that other app could change their implementation at any point.

Instead, you will use what are referred as the “implicit” Intent structure, which looks a lot like how the Web works.

If you have done any work on Web apps, you are aware that HTTP is based on verbs applied to URIs:

Android’s implicit Intent model works much the same way, just with a lot more verbs.

An implicit Intent is made up of two key pieces:

There are hundreds of action strings that are part of the Android framework, such as:

For example, to try to view a Web page, you can use:

startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://commonsware.com")))

We will see a few other Intent actions from the Android framework over the course of the rest of the book, starting with the next section. And, it is possible for apps to define their own custom actions — in that case, if the developers of those apps want you using those actions, they will need to document what those actions are and what they do.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.