I have a React Native application and I am reading accelerometer data each 20ms using the react-native-sensor-manager package.
I start the listener and log it into Reactotron each time it reads data, each 20ms
SensorManager.startAccelerometer(20)
DeviceEventEmitter.addListener('Accelerometer', function (data) {
console.tron.warn(data)
})
It works well if I leave the application in foreground, and even in background, but if I lock the phone it stops reading data. It also stops if I kill the app from the task manager.
How can I achieve to read data even in background?
You would have to tap into creating background processes in order to do anything of that nature.
react-native-background-task is probably the easiest way to do that...however, you will not be able to get updated data at such a fast pace as there are numerous limitations, for obvious reasons, to using background tasks.