Tibor Tibor - 7 months ago 55
Android Question

Android count down timer in background

I have an Android app with manage a countdowntimer (class CountDownTimer) that it is shown in app screen, to show how much time left to arrive 00:00.

My problem now is that when I press home button or when I launch another app the app/timer does not run in the background. So I suspect I must do a service, but how? Colleagues have said to me that I must do something special for when the device gets locked in order for the timer to continue. I want to wake up when arrived to 0.

What is the best way to do this?


You must create your CountDownTimer class and extend it from Service class. By doing so your activity becomes a service and it runs in the background even if you close the application or the screen it doesnt matter it just does the task that you assign to it in the background .