I want to use timer like even when application is shutdown (closed).
I have a timer of 2hrs and the timer will only works when/until I stay on that particular screen and when I press back (way to another screen) then timer not works
Whereas I want to use that timer for 2hrs even when app closed.
Please help to fix it, How to achieve that?
Please reply with blocks image if possible.
By Android Developers,
A foreground service performs some operation that is noticeable to the user. … Foreground services continue running even when the user isn’t interacting with the app. When you use a foreground service , you must display a notification so that users are actively aware that the service is running.
A background service performs an operation that isn’t directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.
Offline method = Use tinyDB to store the time when the timer is started, now whenever you open that screen just call that saved time and compare it with the current time and show the remaining time left
Online method = First of all get current time using any api or extension. Whenever you start the timer/countdown you can save the current time in any online database, now whenever you open the screen again check the current time and also get your saved time. Compare these two and show the remaining time.
You can find tutorials of both of these methods on YouTube as well as on the community.