MobileUsing the New Launchers Supported in Windows Phone 8

Using the New Launchers Supported in Windows Phone 8

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Introduction

Windows Phone platform had support for launchers and choosers in the 7.5 version of the platform; with Windows Phone 8.0, they have extended launcher support to cover even more common tasks.

What are Launchers?

If you are not well versed with the concept of launchers, you can check out our prior publication “How to use Launchers in your Windows Phone 7 applications.

To recap the article in brief, launchers are a way to enable users to perform common tasks.

In the absence of launchers, each application developer would have to implement their own user interface for these common tasks. Launchers provide a common consistent way to do these things and hence it is user-friendly also.

New Launchers in Windows Phone 8

Windows Phone 8 added support for the following new launchers:

  • SaveAppointmentTask – This launcher is used to display a new appointment in the user’s calendar to enable users to add appointments to their calendar from a Windows Phone 8 application.
  • MapDownloaderTask – This launcher is used to allow users to launch the Maps settings application to enable users to download map data for offline use.
  • MapsTask – This launcher is used to allow a user to display a map with the user’s current location as the center.
  • MapsDirectionsTask – This launcher is used to display driving directions.
  • ShareMediaTask – This launcher is used to allow users to share media on social networks.

Besides these new launchers, the previous generation launchers are also supported on Windows Phone 8.

Hands-On

For this tutorial, we will build a multi-page application that will demonstrate a couple of the new launchers introduced in Windows Phone 8.0.

To start off, create a new Visual Studio 2012 project titled WindowsPhoneLaunchersDemo.

Create a new Visual Studio 2012 project
Create a new Visual Studio 2012 project

When prompted, select the default Windows Phone OS 8.0 as the target Windows Phone OS Version.

Target Windows Phone OS Version
Target Windows Phone OS Version

Next, add a couple of button controls on MainPage.Xaml.

Name them such that they appear as in the screenshot below:

Button Controls
Button Controls

Now, add a new page to the project called SaveAppointmentTaskLauncher.xaml.

Add a new page to the project
Add a new page to the project

Add a few controls on that page to make it look like the screenshot below.

Add a few controls
Add a few controls

Now, to wire up this page, include the Microsoft.Phone.Tasks namespace in the code-behind file.

using Microsoft.Phone.Tasks;

We will now write code on the click event for the “Add Appointment” button to invoke our launcher.

private void buttonAddAppointment_Click(object sender, RoutedEventArgs e)

        {

            SaveAppointmentTask sat = new SaveAppointmentTask();

            sat.StartTime =  DateTime.Parse(textBoxStartTime.Text);

            sat.EndTime = DateTime.Parse(textBoxEndTime.Text);

            sat.Subject = textBoxSubject.Text;

            sat.Location = textBoxLocation.Text;

            sat.Details = textBoxDetails.Text;

            sat.IsAllDayEvent = (bool)checkBoxAllDayEvent.IsChecked;

            switch(textBoxAppointmentStatus.Text)

            {

                case "Tentative":

                    sat.AppointmentStatus  = Microsoft.Phone.UserData.AppointmentStatus.Tentative;

                    break;

                case "Busy":

                    sat.AppointmentStatus  = Microsoft.Phone.UserData.AppointmentStatus.Busy;

                    break;

                case "Free":

                    sat.AppointmentStatus  = Microsoft.Phone.UserData.AppointmentStatus.Free;

                    break;

                case "OutOfOffice":

                    sat.AppointmentStatus  = Microsoft.Phone.UserData.AppointmentStatus.OutOfOffice;

                    break;

                default:

                    throw new Exception("Invalid appointment status");

                    

            }

 

            sat.Show();

        }

As you can see above, we instantiated a new object of type SaveAppointmentTask and provided it the details as to the appointment we are seeking and finally, we asked the launcher to be made visible via the Show() api.

Now, we will add another page, which will invoke the MapsDownloaderTask launcher.

Create another XAML page titled MapsDownloadTaskLauncher.xaml.

Create an XAML page titled MapsDownloadTaskLauncher.xaml
Create an XAML page titled MapsDownloadTaskLauncher.xaml

Add a button to it, on the click event of the button, add the following code to invoke the MapsDownloaderTask launcher.

private void buttonMapsDownloadTaskLauncher_Click(object sender, RoutedEventArgs e)

        {

            MapDownloaderTask mdt = new MapDownloaderTask();

            mdt.Show();

        }

 

Finally, we need to wireup these pages from the mainPage. Add the following code to the click events of the button on MainPage.xaml

private void buttonAppointment_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SaveAppointmentTaskLauncher.xaml", UriKind.RelativeOrAbsolute));
        }
 
        private void buttonMapsDownloadTask_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MapsDownloadTaskLauncher.xaml", UriKind.RelativeOrAbsolute));
        }
 

Our application is now ready. If you are having trouble following along, you can download a copy of the sample code for this tutorial below.

When we run the application and click on SaveAppointmentTask, we are presented with the following screen.

SaveAppointmentTask screen
SaveAppointmentTask screen

When you click Add appointment, the following screen is display.

Add appointment screen
Add appointment screen

If you save the appointment, the appointment will now be reflected in your calendar.

Similarly, you can play with the MapsDownloaderTask launcher to see how simple it makes it for an application to directly navigate to the maps setting and download maps of the user’s choice.

Summary

In this article, we learned about launchers in Windows Phone 8. I hope you have found this information useful.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul.patel@hotmail.com

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories