Implicit Intents and Late Runtime Binding

An implicit Intent is a mechanism that lets anonymous application components service action requests. That means you can ask the system to launch an Activity that can perform a given action without knowing which application, or Activity, will do so.

When constructing a new implicit Intent to use with startActivity, you nominate an action to perform and, optionally, supply the URI of the data to perform that action on. You can also send additional data to the target Activity by adding extras to the Intent.

When you use this Intent to start an Activity, Android will —at run time —resolve it into the Activity class best suited to performing the required action on the type of data specified. This means you can create projects that use functionality from other applications, without knowing exactly which application you're borrowing functionality from ahead of time.

For example, to let users make calls from your application you could implement a new dialer, or you could use an implicit Intent that requests the action (dialing) be performed on a phone number (represented as a URI), as shown in Listing 5-2.

LISTING 5-2: Implicitly starting an Activity Available for download on if (somethingWeird && itDontLookGood) {

Wmx.com Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));

startActivity(intent);

Android resolves this Intent and starts an Activity that provides the dial action on a telephone number —in this case the dialer Activity.

In circumstances where multiple Activities are capable of performing a given action, the user is presented with a choice. The full process of Intent resolution is described later in this chapter.

Various native applications provide Activities to handle actions performed on specific data. Third-party applications, including your own, can be registered to support new actions, or to provide an alternative provider of native actions. You'll be introduced to some of the native actions, and how to register your own Activities to support them, later in this chapter.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Responses

  • Doreen
    What is late runtime binding in android?
    7 years ago
  • Raakel Mantila
    Why implicit intent is runtime?
    7 years ago

Post a comment