When
a third-party application runs on a Windows Phone, it runs in an
execution environment that is highly restricted. The Windows Phone OS
must be restrictive in order to protect unsuspecting users of mobile
devices from potential malicious application behavior, which may include
stealing personal data stored on the phone, dialing phone numbers
without users' knowledge, or corrupting other applications' data stores.
One of the major restrictions that Windows Phone OS places on mobile
applications is limiting them to their own execution environment, or sandbox,
and not allowing them access to other applications' space or internals
of the operating system.
Yet many applications need to
access the system features of the phone, to play a music file in the
media library, for example, or to take a photo, or to send a text
message or an e-mail. Windows Phone 7 OS enables such application
interactions with the device via a set of Application Programming
Interface (API) tasks referred to as launchers and choosers.
It is relatively easy to use launchers and choosers from within your
application, but when one is invoked or when a user presses hardware
buttons on the phone, managing application state does get a little
tricky.
Introducing Windows Phone 7 Launchers and Choosers
When an application executes, the
Windows Phone 7 OS confines it to its own space, or sandbox. Both
memory and file storage are isolated within that sandbox—one application
cannot access or alter another's memory or file storage. Neither can
one application directly call another or access a shared data store—such
as a list of contacts, for example. There are obvious reasons for this
behavior; Microsoft must ensure that the Windows Phone 7 platform is as
secure and stable as possible, and isolating applications is one giant
step toward getting there.
There is a set of built-in
APIs that provide access to the most common features of Windows Phone
7. These APIs help us perform tasks, such as saving a contact's e-mail
address or phone number, or placing a phone call (with the mandatory
prior user authorization, of course), that require access to shared
resources on the phone.
Launchers and choosers, which
can be thought of as system functions provided by the Windows Phone OS,
provide you with the means to call into these applications. The
difference between a launcher and a chooser is small but important:
choosers provide a return value into the calling application, whereas
launchers do not. If you think about a task of composing an e-mail
message, for example, then it is sufficient to "fire and forget" an
e-mail application, allowing users to create and send an e-mail. A
launcher is an ideal solution for this task. On the other hand, an
application allowing us to select a photo from the photo library on the
phone needs to pass the selected photo to our application. Windows Phone
7 provides a chooser to perform such a task.
An important concept to
remember is that launchers and choosers are separate applications. Since
one of the core design principles behind Windows Phone 7 is to maximize
battery life, only one application is allowed to execute on the phone
at any time. Therefore, if you invoke a launcher or chooser from within
your application, that launcher or chooser will replace your application
and become the running application. Depending on the circumstances,
your application may enter one of several states when that happens. Tables 1 and 2 list the launchers and choosers available on the Windows Phone 7 platform today. You'll find all of them in the Microsoft.Phone.Tasks namespace; therefore, to use any of them, be sure to import that namespace into your application.
1. Launchers
Table 1
lists launchers offered on the Windows Phone 7 platform, together with a
brief description of functionality offered by each one of those
launchers.
Table 1. Windows Phone 7 Launchers and Their Functions
Launcher | Function |
---|
EmailComposeTask | Launch the e-mail application with a new message displayed. |
MarketplaceDetailTask | Launch the Windows Phone Marketplace client application and display the details page for the specified product. |
MarketplaceHubTask | Launch the Windows Phone Marketplace client application. |
MarketplaceReviewTask | Launch the Windows Phone Marketplace client application and display the review page for the specified product. |
MarketplaceSearchTask | Launch the Windows Phone Marketplace client application and display the search results from the specified search terms. |
MediaPlayerLauncher | Launch the media player. |
PhoneCallTask | Launch the Phone application; use this to allow users to make a phone call from your application. |
SaveEmailAddressTask | Launch
the Contacts application; use this to allow users to save an e-mail
address from your application to a new or existing contact. |
SavePhoneNumberTask | Launch
the Contacts application; use this to allow users to save a phone
number from your application to a new or existing contact. |
SearchTask | Launch the Web Search application. |
SmsComposeTask | Launch the SMS application. |
WebBrowserTask | Launch the Web Browser application. |
2. Choosers
Table 2 lists and describes the choosers available on the Windows Phone 7 platform.
Table 10.2. Windows Phone Choosers and Their Functions
Chooser | Function |
---|
EmailAddressChooserTask | Launch the Contacts application and obtain the e-mail address of a contact selected by the user. |
CameraCaptureTask | Launch
the Camera application and allow users to take a photo from your
application. |
PhoneNumberChooserTask | Launch the Contacts application and obtain the phone number of a contact selected by the user. |
PhotoChooserTask | Launch the Photo Chooser application and select a photo . |