I have the following hook:
useEffect(() => { if (running) { subGyrosocope = gyroscope.subscribe({ next: ({ data }) => { // new data every second payloads.push(data); }, error: e => console.info(e), }); return () => { subGyroscope.unsubscribe(); }; }}, [running]);
I want to also send the data when the App goes to the background. Thats why im starting this Background-Timer in a separat hook:
BackgroundTimer.runBackgroundTimer(() => { console.log('Running! '+ (i++)); payloads.forEach(payload => { console.log('sendToEndpoint'); sendToEndpoint(payload); }); }, 1000);
Now when I start the App the timer also starts and I can go to the Homescreen and the timer is still running, but when I start the hook (changing to running) the timer stops on going to the background.
Also the timer is not sending any data in any app state.But the Observable keeps sending data even when I am in background, so I always get data (and when I reopen the App the data is catching up until its one per second again).
But I want to send the payloads as fast as possible and not only when the app is in foreground. Any idea what I'm doing wrong?
Or any suggestions how I can keep the sendToEndpoint()
-Methode active as long/as often as possible?