Timer running with screen turned off or another application is open

I am continuing the discussion from Timer stop ticking when screen is turned off:
because it didn’t really offered a satisfying answer.

I succeeded in making a timer using a loop with a delay. However, it stops running as soon as I leave the application (when I go back to the home page of my phone for example).
Is there a way to continue the timer without having my application continuously open?
I’d like it to be offline (internet shouldn’t be required to run a timer) and if possible I’d like a sound to be played when the timer reaches 0 seconds (and the screen is turned off).

Thank you very much in advance

I have never tested but if you put as a variable value the time to which tone app is off and you recover this variable when the app is turning back to calculate the time spent.