One of the nice new features available to Windows Phone 7 (WP7) developers in the Mango release is the ability to create reminders and scheduled items. Here's a look at how easy it is to use this feature in your applications.
How to use it in your apps
We can use two types of reminders: the Alarm class and the Reminder class. The difference is in purpose. Alarm works just like the alarms on the phone; they contain minimal information and are designed to let the user know that it's a specific time. You can set the sound used for the Alarm.
Reminder is a richer class. For examples of Reminder, use the calendar to set events. Reminders have a start time and an end time, and allow for titles to be set. When the user chooses "Snooze" on the Reminder, they can pick the time to snooze. And Reminders allow you to provide a URI to an XAML page within your application so the user can be sent to your application to get details on the Reminder.
Let's start with Alarm. First, you will need to add a "using" statement for Microsoft.Phone.Scheduler. Next, create an instance of the class Scheduler.Alarm, and provide it with a name in the constructor. The name will be used to identify it if you ever need to inspect the alarm list or remove it. The name must be unique, so choose it with care. Then, set the following properties:
- BeginTime -- When the alarm should go off
- Content -- The text used on the alarm on the screen
- RecurrenceType -- How frequently the alarm should be triggered (weekly, daily, etc.)
A sample Alarm
This particular alarm was set with the name of "Five Minute Alarm" and a Content of "Reminder text...". As you can see, only the text from Content appears on the screen. After a little bit of testing, I learned that it was best to use a Guid and convert it to a string for the name to ensure uniqueness.Reminders are very similar. In addition to the properties already discussed, you have an EndTime property, a Title (which appears at the top of the reminder window), and a NavigationUri property. Just like a navigation URI within a WP7 app, the URI must be relative. If you specify a NavigationUri, if the user taps the reminder on their screen, it opens your application directly to that page. You can see my sample reminder in Figure B. Figure B
A sample Reminder
As you can see, working with reminders is very simple, and gives your application the kind of deep integration with the OS that provides the kind of smooth, seamless experience for which WP7 is known.
J.JaAlso read: 10 small but impressive ways Mango improves the WP7 experience
Justin James is the Lead Architect for Conigent.