Introducing Pending Intents

The PendingIntent class provides a mechanism for creating Intents that can be fired by another application at a later time.

A Pending Intent is commonly used to package an Intent that will be fired in response to a future event, such as a widget View being clicked or a Notification being selected from the notification panel.

When used, Pending Intents execute the packaged Intent with the same permissions and identity as if you had executed them yourself, within your own application.

As shown in Listing 5-22, the PendingIntent class offers static methods to construct Pending Intents used to start an Activity, start a Service, or broadcast an Intent.

LISTING 5-22: Creating new Pending Intents Available for download on // Start an Activity Intent startActivityIntent = new Intent(this, MyOtherActivity.class); PendingIntent.getActivity(this, 0, startActivityIntent, 0);

// Broadcast an Intent

Intent broadcastIntent = new Intent(NEW_LIFEFORM_DETECTED); PendingIntent.getBroadcast(this, 0, broadcastIntent, 0);

You'll learn more about using Pending Intents indter chapters when they're used to support other Services such as widgets and Notifications.

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

Post a comment