Reviewing the Basic Requirements

The Task Reminder application has a few basic requirements so that it can fulfill what’s expected of it:

check.png The app must be able to accept user input. (Having a personalized task application that doesn’t allow user input would be silly!)

check.png Tasks must be easy to manage.

check.png Every task must have a reminder date and time when the user will be reminded of the task.

check.png The user must be notified of the task when the reminder time has arrived.

check.png Users must be able to delete tasks.

check.png Users must be able to not only add tasks but also edit them.

This application invites lots of interaction between the user and the Android system. The following sections delve into the features that you need to build into the application to give users all the functionality they need.

Scheduling a reminder script (That’s alarming!)

For the Task Reminder application to work well, you need to implement a reminder-based system. The first thing that comes to mind is a scheduled task, or cron job. In the Windows operating system, you create a scheduled task to handle the execution of code and scripts at a given time. In the world of Unix and Linux, you use cron (short for the Greek word chronos, which means time) to schedule scripts or applications.

Because Android is running the Linux kernel, you might assume that Android uses cron to schedule tasks. Unfortunately, Android doesn’t have cron; however, Android has the AlarmManager class, which accomplishes the same task. The AlarmManager class lets you specify when your application should start. An alarm can be set as a single-use alarm or repeating. The Task Reminder application uses AlarmManager to remind users of pending tasks.

Storing data

All the activities, task data, and alarms needed to make the Task Reminder app work are stored in these locations:

check.png Activities and broadcast receivers: In a single Java package

check.png Task data: In a ContentProvider backed by a SQLite database

check.png Alarm info: In the AlarmManager via the intent system after being pulled from the ContentProvider

Distracting the user (nicely)

After an alarm fires, the app has to notify the user of the alarm. The Android platform provides mechanisms to bring your activity to the foreground when the alarm fires, but that isn’t an optimal notification method because it steals focus from whatever the user is already doing. Imagine if the user is dialing a phone number or answering a phone call and an alarm fires that brings an activity to the foreground. The user is likely to be confused because an activity started that he didn’t initiate manually.

You have two ways to grab the user’s attention without stealing the main focus away from the current activity:

check.png Toast: A small view that contains a brief message for the user. The message doesn’t persist because it’s usually available for only a few seconds — a toast never receives focus. The Task Reminder app uses a toast not for reminding the user but uses it instead for notifying the user when her activity has been saved.

check.png Notification Manager: The NotificationManager class notifies a user that events have taken place. They can appear on the status bar at the top of the screen. Notification items can contain various views and are identified by icons you provide. The user can slide down the notification list to view notifications. The Task Reminder application uses the NotificationManager class to handle alarms. (See Chapter 1 if you’re unsure how the notification area works.)

remember.eps You can grab a user’s attention by displaying a dialog box that immediately steals the focus from the already running app. Despite its effectiveness, the user may become irritated because your app is stealing the focus (possibly continually, for numerous reminders) from the current action in another application.

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

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