Firstly, you can use storage to save the current time (and also total duration). Then, here is the next scenario:
When the timer starts by the user, can save something to Shared Preferences (which can be the simplest solution) that will record the current time and total duration of your countdown.
When the app is locked or running in the background, use the code you currently have. If the user restarts the application, you can check with your code (you can use your saved values for storage).
Then, you can write calculation logic according to your shared values which are duration and current time accordingly.
This might address your issue because when the app is background, you can use only these values to control your timer.