Run the app in background

Hi there!
I’m developing a new version of an app that is a kind of stopwatch that after some amount of time make a step or reach a checkpoint. This stopwatch should be run hours and hours without stop.
When the app works in foreground there are no problems but when the app pass in background some strange happens and after a some amount of time seems that the app is killed, and when I come back to the app it’s restarted.
How I can “freeze” and come back at the last state/view/modal, is possible do this?
How can I do to solve this problem?
I don’t necessarily need that the app stay running in background because I only need to know when the stopwatch was started…
Thanks in advance!

You should check out this repo