I am building a running app that shows a timer. When the timer reaches 0 seconds a sound is played. I use React Native Sound for playback. I use an interval on componentDidMount for counting the seconds:
componentDidMount() { this.recalcTotalSeconds(); KeepAwake.activate(); this._interval = setInterval(() => { this.step(); }, 999);}
It works nicely as long as the phone is unlocked. When the phone is locked the interval is not fired and the sound is not played. As a first measure I uploaded a version with Keep Awake that prevents the screen from locking. I am looking for a battery-friendly solution.
How can I set a timeout to wake the phone up or at least play a sound to alert the user to unlock the phone? How can I play sound in the background when the phone is locked?