GucciProgrammer
GucciProgrammer

Reputation: 191

Is it possible to have a count down timer continue running even after the user has closed the app

Im thinking of having an android app that has a count down timer. However, i need this timer to be running too even if the user kills the app and once the count down timer reaches 00:00:00, it triggers an action regardless of the application being active. Is there a possible solution to that?

Upvotes: 0

Views: 1168

Answers (3)

Supriya
Supriya

Reputation: 1098

using services will be the best option for your requirement. OnFinish of the timer, you can trigger your action.

Upvotes: 1

vishal jangid
vishal jangid

Reputation: 3025

*

Yes it is possible. use a service , your service will continue to run even if app is closed. you should call a service using AlarmManager with in a fix time . *

Upvotes: 1

Misagh Emamverdi
Misagh Emamverdi

Reputation: 3674

Yes it is possible. Just run on background thread so your thread will continue to run even if app is closed.

Using service is a good idea but you have to work in background thread even in service. Because services work in foreground thread by default.

In your case I think the best way to do that is using AlarmManager. Try it.

In Both case (service and alarm) reboot will kill your thread. However you can recreate it. You can use services that will start again if they get killed. Also you can set a BroadCastReceiver that will be called after reboot is complete. So you can recreate your timer in onReceive method.

Upvotes: 1

Related Questions