Search code examples
androidandroid-studioservicecountdowntimerandroid-api-levels

How to run my Countdown Timer in Service in Latest API Level?


As we know latest API level in android version don't allow long background task in application. So, how can I run my 12 Hours countdown Timer in background because I have to do some task on Timer finish. So How can I achieve this.


Solution

  • The right way to schedule tasks based on time or certain constraints (e.g when device is idle, or when it is charging etc) is by using WorkManager. Take a look at it: https://developer.android.com/topic/libraries/architecture/workmanager/

    Specifically, for recurring tasks, have a look at this section: https://developer.android.com/topic/libraries/architecture/workmanager/basics#recurring