Search code examples
androidalarmmanagerrepeat

what is the most efficient(battery) way to repeat an action in android?


I searched all stack-overflow and Google and I found that their is couple of ways to do it. The best and most suitable way that I found is Alarmmanger. But I think that it consumes the battery cause I use it with RTC_Wakeup.

My app runs the function every defined time (it can be 1 min till 1 hour, User choice). The function needs to run even if the app dosen't.

What the best way to do without consuming a lot of battery power?


Solution

  • AlarmManager is really the best option for you. You clearly need a service to trigger your app on, as you want your action to execute when your app is not launched. The only way to achieve this is a pending intent and alarm managers barely does anything else than handling pending intents.