Windows Phone – Launchers & Choosers

June 30, 2011 — Leave a comment

Launchers and Choosers have been around since the first version of Windows Phone and basically allow the developer to integrate into the operating system.  For example, there is a ‘Task’ to make a phone call or to compose an email.  I like to define Launchers & Choosers as follows

  1. Launchers – ‘Just Launch it and Forget it’ – Basically, you launch something out the the OS, possibly passing some parameters and hand control over to the operating system.  Don’t expect the user to always come to your application and at this point you will be tombstoned or go into dormant state.  For example, you launch a phone call, the user might hit the start button, and go to another application and never return to your app until it’s needed again
  2. Choosers – this lets you pull information from the operating system in a way that keeps the users data secure and private.  For example, you can ask the user to select a contact and it will return contact information.

With Windows Phone Mango tools out, there are some new Launchers and Choosers that can be of use to developers.  You will find all of them un der the Microsoft.Phone.Tasks namespace on MSDN.  I’ll just go through a summary of the new ones for Mango.

The Launcher Tasks

As developers we did not really get that many new launchers but the ones we got I think will be useful if you are creating mapping applications.

image

The class names are pretty self explanatory but essentially the three do the following

  1. BingMapsDirectionsTask – Will show directions for using the Maps application
  2. BingMapsTask – will start the Maps application at the defined center point and if a search term is passed in it will add pins on the map that match the search term.

There is also a LabeledMapLocation class that is used with the BingMapsDirectionsTask that is basically a latitude/longitude with a string label

image

And using these are straight forward.  To use the BingMapsDirectionsTask you can use the following code

which will result in the following in the Maps application using the emulator

image

BingMapsTask is just as easy

And results in

image

 

The Chooser Tasks

In Windows Phone Mango, we have four new chooser tasks.  Remember, choosers will return something back to us via a Completed event.

  1. AddressChooserTask – allows you to get the address of a contact chosen by the user
  2. SaveContactTask – allows you to initiate a save contact for the user to complete
  3. GameInviteTask – allows you to show the game invite screen to allow user to invite someone else to a multiplayer game session
  4. SaveRingtoneTask – allows you to initiate a save ring tone for the user to complete

I’ll do a quick example on saving a contact.  Essentially you have to create a new SaveContactTask, fill in some properties and call the show event.  The possible properties are

image

and the sample code to save is as follows

and our completed event handler is as follows

which results in

image

and when the user is done, because we wired up the Completed event we will get the appropriate message if the user saved the contact or not.

The Share Tasks

You are probably wondering what the heck is a ‘Share Task’.  Well this is essentially a Launcher but it’s new to Mango and allows you to share the user’s status (ie Facebook status updates) or share a link.

  1. ShareStatusTask – allows user to share a status message on social network of choice
  2. ShareLinkTask – essentially same as status but will share a link on social network of choice

and the object model looks like this

image

Unfortunately this doesn’t work in the emulator but basically what happens on a device is a “Post Message” page pops up, user can select which social network they want to post to and click send.  They do have to option of modifying the post.

So there you have it, some of the new Launchers & Choosers available in Mango.  I think they are useful and already have plans to integrate into some of our apps and customer apps.

Enjoy!

No Comments

Be the first to start the conversation.

Leave a Reply