Recently I have been working on a simple application that should have the ability to start itself after a period of time, after the application is closed. Hopefully, it turned out that this is quite simple to implement, and to achieve this, the AlarmManager in conjuction with a BroadcastReceiver can be used.
The basic idea is as follows: the AlarmManger registers an intent, when the alarm goes off, the intent that had been registered automatically will start the target application if it is not already running. The BroadcastReceiver will be listening for that intent, and when the intent is received, it will start the desired activity from the application.
The broadcast receiver implementation looks like this:
Register the OnAlarmReceive in the AndroidManifest file:
And finally, here’s how to setup the alarm:
The last line from the code – finishing the current activity – is optional of course, but in case…
View original post 51 more words