Windows Phone Multitasking–Scheduled Notifications

June 28, 2011 — Leave a comment

In my previous post I talked about some of the new multitasking features available in Windows Phone Mango.  In this article, I’ll go over Scheduled Notifications in a bit more detail.

You will find all API details in the Microsoft.Phone.Scheduler namespace and the main items we will look at are

A Scheduled Notification is fairly straight forward and essentially will popup a dialog box similar to the calendar reminder in the OS.

There are two types of Scheduled Notifications you can use and these are Alarm and Reminder. This is a good way to integrate with the native OS and not have to build basic pop ups but leverage what is already there.

I’m not going to go through an entire code walk through as there is a good example on MSDN on how to create reminders for Windows Phone. Here is a quick sample on creating a reminder

Running this code on the emulator will result in the following

image_thumb[2]

Not overly complex but a few key things to note

  • You can specify a NavigationUri which will be used if the user launches your app from the reminder. This way you know if you came from the reminder and can show the specific reminder that was clicked
  • Don’t try to add a reminder with the same name, you will get an exception saying that the reminder already exists

Creating an Alarm is almost the same as creating a Reminder with a few slight differences.

//Create an alarm Alarm alarm = new Alarm(“Test Alarm”); alarm.Title = “My Alarm Title”; alarm.Content = “My Test alarm”; alarm.BeginTime = DateTime.Now.AddSeconds(10); alarm.ExpirationTime = DateTime.Now.AddSeconds(15); alarm.RecurrenceType = RecurrenceInterval.None; alarm.Sound = new Uri(“”);

//Add the reminder to the ScheduledActionService
ScheduledActionService.Add(myReminder);

Again, pretty straight forward but a few key things to note with alarms are

  • A user cannot click from the alarm to your application so you have no NavigationUri property
  • You can specify a custom sound to play using the Sound property but the sound file must be included in your XAP and cannot be played from isolated storage.

Scheduled notifications I think will be useful in some application scenarios and it’s great that we as developers can offset some of the ‘reminder code’ to the API/OS to handle for us.  This is just one of the ways Windows Phone now multitasks and I’ll follow up with the others in upcoming posts.

No Comments

Be the first to start the conversation.

Leave a Reply