Reviewing the Basic Requirements

The idea behind the Task Reminder application is to remind users through the use of an alarm system that a task must be performed. It will allow users to create a list of time-sensitive tasks, and to set a date and time for the app to remind them of these tasks. To fulfill what is expected of it, the Task Reminder application has a few basic requirements:

  • It must be able to accept user input — having a personalized task application that does not allow user input would be silly!
  • Each task must have a reminder date and time in which the user will be reminded of the task.
  • The user must be notified of the task when the reminder time has arrived.
  • Users must be able to delete tasks.
  • Users must be able to not only add tasks but to edit them.

That's alarming! Scheduling a reminder script

For the Task Reminder application to truly work, you need to implement some sort of reminder-based system. As a developer, the first thing that comes to mind is a scheduled task or cron job — methods to handle the scheduled execution of code or scripts in the Windows operating system and the UNIX/Linux operating systems, respectively. Although Android is running the Linux 2.6 kernel, it does not have cron. However, it has the AlarmManager class, which achieves the same thing. The AlarmManager class allows you to specify when your application should start in the future. Alarms can be set as a single-use alarm or as a repeating alarm. You will set the alarm as a single use alarm. This should be perfect for your Task Reminder application.

Storing data

You are exposed to many new features and tools in this application. You may be wondering where to store the activities, the task data, the alarms, and so on. You can choose from the following locations:

  • Activities and broadcast receivers: In one Java package
  • Task data: SQLite database
  • Alarm info: Pulled from the SQLite database and placed in the AlarmManager via the intent system

Distracting the user (nicely)

After an alarm fires, you need to notify the user. Although Android provides mechanisms to bring your activity to the foreground when an alarm fires, this is probably not the best approach. Interrupting the user in this way may cause the user to be irritated or confused because an activity started that he did not initiate. However, you can grab the user's attention in other ways, including the following:

  • Toasts: A toast is a small view that contains a quick message for the user. This message does not persist because it is usually available for only a few seconds at most. A toast never receives focus. I won't use a toast for reminding the user, but instead I use a toast to notify the user when her activity has been saved so that she knows something happened.
  • Notification Manager: The NotificationManager class is used to notify a user that an event or events have taken place. These events can be placed in the status bar, which is located at the top of the screen. The notification items can contain various views and are identified by icons that you provide. The user can slide the screen down to view the notification.

The best approach, then, to handle the alarms for the Task Reminder application, is the NotificationManager class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.248