Thursday, July 28, 2011

Start custom Service when Android starts up

Another interesting part of the RemindMe development is considering what happens when the phone is powered up.
The Reminder service must be "woken up" for it to be useful.

The way to do this, is to create a receiver, and hook it up to the android action BOOT_COMPLETED

In the AndroidManifest.xml, declare the following receiver:



With this, every time the phone is powered up, after boot is complete, AlarmBroadcastReciever will be called, which sets up the inexactRepeatingAlarm mentioned in my previous post.

Wednesday, July 27, 2011

Android Reminder Application Development

I started working on a simple reminder application for Android.
The idea is to gain some experience in android development, and also to try to create a useful tool.

You can find the latest version here: RemindMe

I'm still working on it, I won't post the complete code here as it might change, but feel free to email me and I'll provide the latest version.

The idea of the app is to create a tool that can set up simple text reminders, independent of the actual time.
For example, to be able to say "remind me in two hours" and you don't have to configure when that is, just the delay.
It also allows for daily reminders.

The design is fairly straightforward: A SqlLite database to store the notifications, the application to create them, and the task to poll the database and alert the user.

One thing particularly interesting here is how to schedule the task to check for expired notifications.
The way to do this is to set up an AlarmManager and utilize the setRepeating() method.
But there's also a setInexactRepeating() method that allows to set the time, though the android system does not necessarily fire it at the exact moment, but might wait and group different alarms that happen around the same time, and then fire them all at once, making it more power-efficient.

This is how the wake up alarm is set up for the Reminder:



What this does is set up a timer to check for expired reminders every 30 seconds, but not necessarily exactly in 30 seconds, more likely when android wakes up and has some task to perform.

The app is free in the market, and i'm open to suggestions on how to improve it!