background fetch not working with accelerometer in react native expo

im using below code to fetch the accelerometer values when my app is running in the background i have added the below code ouside of the app component

TaskManager.defineTask('firstTask', async ({ data, error }) => {
  if (error) {
    // Error occurred - check `error.message` for more details.
    return; 
  }
  if (data) {
    Accelerometer.addListener(accelerometerData => {
      console.log(accelerometerData);
      Accelerometer.setUpdateInterval(10000);
     })
    console.log('locations')
  }
});

the below code is inside of the app component

useEffect(() => {
    RegisterBackgroundTask();
   }, []);

  const RegisterBackgroundTask = async () => {
    try {
      await BackgroundFetch.registerTaskAsync('firstTask', {
        minimumInterval: 5, // seconds,
      })

      console.log("Task registered")
    } catch (err) {
      console.log("Task Register failed:", err)
    }
  }

when i console log something the background app works meaning when i close my app the console.log will display on the console but when i add the acceleromenter nothing happens

Any idea on what i should do

Hey @suhail_misbah, what platform(s) and versions is this happening on?

Cheers,
Adam

hai @adamjnav i using this for android and am using react native expo sdk40

@adamjnav do u think u can help me please

hai can u help me with this issue

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.