I'm facing an issue with BackgroundTimer. When running the app on the development server (npx expo run:android), it continues working in the background for several minutes without issues. However, after building the APK and installing it, the app freezes after about 40 seconds in the background and sometimes even gets killed if left in the background for too long. Why is it behaving differently in the development environment compared to the production build?
I tried older react-native-background-timer and also newer @boterop/react-native-background-timer. These two packages had a same issue.
const stopTimer = () => {
if (Platform.OS === 'ios') {
clearInterval(timer)
BackgroundTimer.stop();
} else {
BackgroundTimer.clearInterval(timer);
}
};
useEffect(() => {
if (isTimerRunning && !isPaused) {
if (Platform.OS === 'ios') {
BackgroundTimer.start();
timer = setInterval(() => {
setTimerSeconds(prevTime => prevTime - 1);
checkTime()
}, 1000);
} else {
timer = BackgroundTimer.setInterval(() => {
setTimerSeconds(prevTime => prevTime - 1);
checkTime()
}, 1000);
}
}
return () => {
if (Platform.OS === 'ios') {
clearInterval(timer);
BackgroundTimer.stop()
} else {
BackgroundTimer.clearInterval(timer)
}
};
}, [isTimerRunning, isPaused, timerSeconds, setTimerSeconds]);