How to use timer even after app closed

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.
Thanks!

use clock component and in blocks

Set clock1 timer always fires to true

Will clock timer always fire to true help him to run it even after app is closed @Faraz_Firoz1 ??


I think it will need Foreground Service or Background Service (IDK which) which can be achieved by this extension.

If it can be achieved by Background Service then you can use this free extension.
Background Tasks extension 2.0 A [Experimental] - Extensions - Kodular Community

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.

When someone want to close screen then enable timer always fire from block, in button or back press event. If your work finished

Actually, this is for 2 hours (timer) and nobody stay for 2hours on single screen or single application for such long time,

So please provide a solution, for timer stay enables and works when app is closed.

By-the-way Thanks for taking interest in this topic.

Many reason for this method, which task you want to do by using clock?

This post was flagged by the community and is temporarily hidden.

You should’nt promote video with non-english language.

I’m using this method also but this is not working when screen back press or closed the app

I’m looking for method that works when app closed

It’s not my video I am just trying to help

What about saving time in tinyDB and when he reopen the application, use math logic to find out diffrence in time.

you can do this using 2 methods =

  • 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.

2 Likes