Task programming model on Windows Phone

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Windows Phone provides several out of the box dialogs/pages which helps a user to compose some task like camera capturing or sending of an email.
Such actions are called tasks in WP programming model. Because applications are not able to directly access common stores of information, such as the contacts list, and to directly invoke other applications, such as the phone or messaging. To enable scenarios that require common tasks such as these, Windows Phone exposes a set of so called launcher and chooser APIs.
One chooser is an action of type fire and forget. For example Send SMS or Open some Web Page. In contract one launcher is an action which returns some information like select contact.

Supported Launchers

· EmailComposeTask 
  Use this to allow users to send email from your application

· MarketplaceLauncher
  Allows an application to launch the Marketplace application

· MediaPlayerLauncher
  Allows an application to launch the media player

· PhoneCallTask
  Allows an application to launch the Phone application; use this to allow users to make a phone call from your application

· SearchTask
  Allows an application to launch the Web Search application

· SmsComposeTask
  Allows and application to launch the SMS application

· WebBrowserTask
  Allows an application to launch the Web Browser application

Supported Choosers

· SaveEmailAddressTask 
  Use this to allow users to save an email address from your application to a new or existing contact.
· SavePhoneNumberTask 
  Use this to allow users to save a phone number from your application to a new or existing contact

· EmailAddressChooserTask - Allows an application to launch the Contacts application; use this to obtain the email address of a contact selected by the user

· CaptureCameraTask - Allows an application to launch the Camera application; use this to allow users to take a photo from your application

· PhoneNumberChooserTask - Allows an application to launch the Contacts application; use this to obtain the phone number of a contact selected by the user

· PhotoChooserTask - Allows an application to launch the Photo Chooser application; use this to allow users to select a photo


Technically, one task on Windows Phone is a class which derives from ChooserBase<TTaskEventArgs>.

public abstract class ChooserBase<TTaskEventArgs> where TTaskEventArgs
: global::Microsoft.Phone.Tasks.TaskEventArgs
{
        //     Occurs when a chooser task is completed.
        public event EventHandler<TTaskEventArgs> Completed;

 

       //     Call this method to raise the Completed event.
        protected void FireCompleted(object sender, TTaskEventArgs e, Delegate fireThisHandlerOnly);

        //     Launches and displays the chooser.
        public virtual void Show();

}

In fact, one task can be “Shown” and finally completed. So, if you want the user take a picture call CameraCaptureTask.Show(). After the user is finished, you can be notified by subscribing of event Completed.

In contrast Launchers do not have a base class. They all provide static method named Show().

All choosers and launchers are implemented in assembly Microsoft.Phone, Version=7.0.0.0:.
Personally I think that naming of choosers and launchers is inconsistent. Moreover Launchers do not derive from some base class, some of them have instance Show() method and some static Show() method.
I would regard more consistent model for Choosers and Launchers. This would give as ability in the future to build distributable Choosers and Launchers in the marketplace and to reuse them across applications. Imagine TVChanelLauncher or GeoLocationChooser.


Posted Aug 23 2010, 11:34 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.