Windows Phone 7 (Mango) Tutorial - 17 - How to Create a WP7 Reminder Application?


Yesterday we discussed about the Alarm class and also demonstrated the use of it using a small demo app. Today in this post we will learn about Reminder class and will see the structure of the same. We will also demonstrate the implementation with a small demo.

 

Like Alarm class, Reminder class is also part of the "Microsoft.Phone.Scheduler" namespace and inherits the same base class. Let's read more about it and explore each and every step to create a simple Windows Phone 7 Reminder application.

 

Index - Windows Phone 7 (Mango) Tutorial

 

Know about Reminder Class

Reminder class is part of "Microsoft.Phone.Scheduler" namespace and inherits from ScheduledNotification. We already learned about the base classes yesterday, so will not discuss about them more here. If you didn't yet read the previous chapter, read to learn more about the base classes.

 

Here is the diagram of the class structure, which will give you better visibility:

 

WP7.1 Demo - Reminder Class Structure

 

 

In the above diagram, you will come to know a little change between the class "Alarm" and "Reminder". The alarm class exposes two properties called "Sound" and "Title", but here the Reminder class exposes property named "NavigationUri". You can set it to navigate away to a page of your choice.

 

Create the Basic Application UI

Like previous example, we will create the similar application UI which will have a TextBox to enter the delay time and two buttons to set and reset the reminder. Here is our XAML code for your reference:

 
<!--ContentPanel - place additional content here-->
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Center">
        <TextBlock Text="Set Time (Sec) : " VerticalAlignment="Center"/>
        <TextBox x:Name="txtTime" Width="150"/>
    </StackPanel>
    <StackPanel Orientation="Vertical" Margin="5" HorizontalAlignment="Center">
        <Button Content="Set Reminder" Width="300" Height="70" Click="SetReminder_Click"/>
        <Button Content="Reset Reminder" Width="300" Height="70" Click="ResetReminder_Click"/>
    </StackPanel>
</StackPanel>

 

Implement the Reminder Feature in Code

This is also similar to the previous example. Instead of creating the Alarm class instance, we will create instance of Reminder and pass the name of the reminder in the constructor. Enter the message that you want to display in the content and assign the BeginTime of the Reminder dialog.

 

At the end, set the instance to the ScheduledActionService to run the app in the background. Find the code implementation below:

 
private static void CreateReminder(double time)
{
    var reminder = new Reminder("MyReminder")
                    {
                        Content = "You have a meeting with your team now.", 
                        BeginTime = DateTime.Now.AddSeconds(time)
                    };
 
    ScheduledActionService.Add(reminder);
}
 
private static void ResetReminder()
{
    ScheduledActionService.Remove("MyReminder");
}

 

It is require to remove the instance from the service at the end of the operation as shown above. As it is a demo app, we will not handle everything here. Hence, before setting the reminder for the 2nd time onwards, remove it from the service.

 

Demo

It's time to demonstrate our example. Build and run the application. Once the app run and the main UI comes up, it will look similar to the below screenshot:

 

WP7.1 Demo - Reminder Application Main UI

 

Enter the time (in seconds) into the TextBox and click "Set Reminder" button. Let us enter 1 sec duration there. Once we click the button, you will see the reminder screen pops up in the screen immediately. You can set any time but the bigger no. you enter, you have to wait for that much time before seeing the Reminder screen.

 

This will look as shown below in the first figure. You can notice that, unlike the alarm Window this screen has a snooze time settings. You can snooze the reminder for 5 mints, 10 mints, 1 hour, 4 hours or 1 day. Clicking on the snooze box will expand the list as shown in the second screen shown below:

 

WP7.1 Demo - Reminder Window with Snooze Time Settings

 

Chose your desired option and click snooze to popup the reminder after specified time of interval. Click dismiss to cancel and close the screen.

 

Points to Remember

Unlike Alarm window, you can set the Title of the screen here. You can assign the title of the Reminder window as per your need. Have a look into the below code snippet and screenshot for details:

 

WP7.1 Demo - Setting Reminder Window Title

 

Hope, this chapter was helpful to you to understand the feature. As the reminder process runs in the background, you will notify if you exit the application too.

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

8 comments

  1. Hi,

    Reminder also has NavigationUri, which can be used for deep linking into the application. If you provide it, the user will be able to navigate to specific application's page on reminder header click :)

    Best,
    Alex

    ReplyDelete
  2. hi , How are you putting snooz time selection option ??
    I am not getting this,,

    Following is my code snippet
    Alarm _Alarm = new Alarm("Alarm");
    _Alarm.Content = "You have a meeting";
    _Alarm.BeginTime = DateTime.Now.AddSeconds(2);
    _Alarm.RecurrenceType = RecurrenceInterval.Daily;
    ScheduledActionService.Add(_Alarm);

    ReplyDelete
  3. Unfortunately that API is not yet available to program.

    ReplyDelete
  4. I have a question
    In the reminder demo can you set different wav files to play with this? So if you want to create an alam that plays wav files contained in your app (not the default wp7 alarm sounds)?

    ReplyDelete
  5. can collection can be used in a wp7 project?

    ReplyDelete
  6. i really need your help..i dont know how to make this application keeps remind me without i set the time's reminder again....

    ReplyDelete
  7. No you can't. Once the user clicks "Dismiss", it will be remove from the SchedulerService.

    ReplyDelete
  8. Hello kunal,
    How do i enable or Disable reminders in WP7. There is a IsEnable Property in Reminder but i am unable to set value to it .

    Thank you

    ReplyDelete

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top