Refining AlarmManager behavior in Android

I see all the AlarmManager examples set by Activity.

My question is this: If my application sets up a repeating AlarmManager, does this persist even after the running application is closed and deleted from memory?

If not, how do I run AlarmManager at a lower level, which Android starts at boot, and if it ever fails or dies or throws an exception, restarts without having to do anything?

Finally, if the action that I want to perform for BroadcastReceiver does not have visual components, do I still need to create a separate Activity for it? In my case, I want there to be a background bootloader that wakes up and looks into the folder, and if it sees the files in this folder, sends them to the server. I do not need user feedback.

So, my ideal would be to have a magical, OSM-based AlarmManager that calls an IntentService that just handles loading, but I don't understand how to get such an AlarmManager to work in the first place.

TIA

+6
android alarmmanager
source share
2 answers

Yes, AFAIK alarms โ€œsurviveโ€ and continue to fire even after the action that recorded them ends. But they canโ€™t stand the phone rebooting.

If I understand your problem correctly, I think you can achieve what you are looking for by creating a project with a broadcast receiver that listens for android.intent.action.BOOT_COMPLETED intent, and then (re) logs a repeating alarm that triggers in turn service (Intent) to download.

You do not need activity, but you might want it anyway, so that the user temporarily disables the loading mechanism by checking the box or something like that. It would probably be nice to let the user select the frequency of your alarm, that is, how often should the service start and look for new files to download. It will also be a good place to register your alarm for the first time.

+10
source share

I agree with Nikolai that you will have 2 broadcast receivers in your application:

  • which will re-register the boot alarm
  • which starts your service when an alarm is triggered

You may still have activity, but it should not be triggered by the alarm receiver (hence the service): instead, you may receive a notification when the service starts, when the user is able to start this operation from an extended notification message.

perhaps also think about setInexactRepeating (instead of setRepeating) for your alarm clock, as well as using a workflow to handle long downloads (in case the user wants to use your activity in the main thread at the same time).

+1
source share

All Articles