Search code examples
javaandroidalarmmanagertimertask

android timertask alternative for longrunning BackgroundService


im looking for a alternative to java.util.TimerTask.

My app should start random notifications over a month.

The TimerTask can only handle one, after that it doesnt work anymore.

Does it need to get called from a backgroundService? Or is something like AlarmManager enough?


Solution

  • You need to use AlarmManager for scheduling tasks in this time range. There is an official training doc in the Android documentation that you might find interesting: https://developer.android.com/training/scheduling/alarms.html

    Another possibility for scheduling tasks with longer periods is JobScheduler, though that's more tailored for scheduling network jobs.