Search code examples
androidalarmmanager

Android: AlarmManager running every 24h - is it save to start only once?


i couldnt find an answer to this question. I have a task to perform every 24h and i could either start the Pending Intent everytime i start the app, or i could start it once by testing with a boolean.

Its probably not good, performance wise, to unnecessarily start the Pending Intent so often, but starting it only once seems so fragile to me. I heard that Samsung phones shut down Alarm Intents after 3 days of not using the app?


Solution

  • If you want a task to be done often, and for the long term, I would suggest moving away from AlarmManager.

    AlarmManager will not work if the device is rebooted, I would suggest looking into JobScheduler which handles this case, or if you want to support backwards compat, you should look into Firebase's Dispatcher which will handle this for you.

    I'm unsure what kind of task you actually want to do every 24 hours, but you should be fine passing Intents.

    I personally use Firebase's Dispatcher for my app to sync to the server every 24 hours.