If you’re developing a mobile app that requires an event reminder feature, or are curious to expand your toolbox of development knowledge, this post is for you. As the mobile app industry is still in its infancy stage, I find developing mobile apps challenging and fun, and brings out the innovator in all of us.
In this post, I will
- Discuss common event reminder concepts and requirements,
- Provide a solid and effective design,
- Discuss details implementing this design using the Android platform, and
- Provide source code, i.e., classes, depicting the implementation
Note: Since a full working application is not provided, I leave it to the reader to wrap this feature within the appropriate activities and provide a user friendly interface to manage event reminders.
Event Reminder: Requirements
Event reminders simply remind us of an upcoming event. The most common events are birthday’s, holiday’s, and meetings.
Most of us use a calendaring tool, such as Google Calendar or MS Outlook to set event reminders from our laptops and desktops. We are reminded of an event via an alert, usually displayed as a dialog box and, possibly sound, to get the user’s attention.
Event reminders are easily added, and allow us to specify a period of time in advance of the event, to alert us of the upcoming event.
In this post, we are interested in moving the event reminder feature into a mobile app. At this time, we are not interested in sync’ing event reminders to an existing calendaring tool. That is, we are only interested in developing a stand-alone event reminder feature that runs on a mobile device. Our requirements are as follows:
- Ability to add and delete event reminders
- Ability to specify when an event reminder occurs, e.g., one week or one day before the event
- Ability to generate and receive alerts that notify the user that an event reminder has occurred
- Alerts should take advantage of native mobile device notification features, e.g., emit sound, emit LED flash, vibrate
- Ability to view alerts any time after event reminder has occurred
- Ability to access and display event details when viewing an alert
- Ability to delete alerts
Event Reminder: Design
To effectively implement event reminders, components providing the following high-level functionality are necessary:
- Management of event reminders
- Background servicing, or periodic polling, of event reminders, and generating an alert when a reminder has occurred
- Notification of alerts to the user
- Management of alerts
Consider the following Class Diagram depicting a design of the event reminder feature:
Note that the EventReminderAlarmService, EventReminderAlarmReceiver, and EventReminderAlertCheckTask are required to properly service and broadcast alerts using the Android platform. Each inherits functionality as follows:
- EventReminderAlarmService extends Service
- EventReminderAlarmReceiver extends BroadcastReceiver
- EventReminderAlertCheckTask extends AsyncTask
Also, the AlertNotificationHelper class contains simple methods that provide a facade to the Android notification features. When we need to alert the user of the occurrence of an event reminder, we use this class to effectively make a sound, flash the LED’s, and vibrate the device.
Event Reminder: Implementation Details
The EventReminderAlarmService class is a true Android Service that periodically checks for the occurrences of event reminders. The actual occurrence checks are done in the EventReminderAlertTask class. An EventReminderAlert instance is created for each event reminder occurrence found.
The EventReminderAlarmService class is as follows:
public class EventReminderAlarmService extends Service implements IDebugSwitch {
public static final String NEW_ALERTS_FOUND = "New_Alerts_Found";
private AlarmManager alarms;
private PendingIntent alarmIntent;
private EventReminderAlertCheckTask alertCheckTask = null;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// todo: alertsEnabled should be read as a user preference/setting
boolean alertsEnabled = true;
long updateFreq = 24*60*60*1000;
if (alertsEnabled) {
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeToRefresh = SystemClock.elapsedRealtime() + updateFreq;
alarms.setRepeating(alarmType, timeToRefresh, updateFreq, alarmIntent);
}
else {
alarms.cancel(alarmIntent);
}
refreshAlerts();
return Service.START_NOT_STICKY;
}
@Override
public void onCreate() {
alarms = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
String ALARM_ACTION = ReminderAlertAlarmReceiver.ACTION_REFRESH_ALERT_ALARM;
Intent intentToFire = new Intent(ALARM_ACTION);
alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
private void refreshAlerts() {
if (alertCheckTask == null ||
alertCheckTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
alertCheckTask = new EventReminderAlertCheckTask();
User user = Logon.retrieveUser(getApplicationContext());
alertCheckTask.execute(user);
}
}
}
And the EventReminderAlarmReceiver class is as follows:
public class EventReminderAlarmReceiver extends BroadcastReceiver {
public static final String ACTION_REFRESH_ALERT_ALARM = "com.iqspike.eventreminder.service.ACTION_REFRESH_ALERT_ALARM";
@Override
public void onReceive(Context context, Intent intent) {
Intent startIntent = new Intent(context, EventReminderAlarmService.class);
context.startService(startIntent);
}
}
It is important to note that some entries are required in the AndroidManifest.xml file as follows:
<service android:enabled="true" android:name="com.iqspike.eventreminder.service.EventReminderAlarmService"/> <receiver android:name=".EventReminderAlarmReceiver"> <intent-filter> <action android:name="com.iqspike.eventreminder.service.ACTION_REFRESH_ALERT_ALARM"/> </intent-filter> </receiver>
More coming soon!









