Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29741

Expo dev tool: Running Dev app in the background

$
0
0

This my first time developing in Expo, I'm building app that trace the location and send the data to server every 5 sec using node. I'm using TaskManager API from expo I'd follow everything and it works I'm getting the data. But when I put my app in the background it stops the console.log(data).

Is this should be running (the TaskManager) in background task even in Dev environment using Expo Dev Tool or is it needed to put to production mode bofore it works?

When I turn the app into background mode like this, my console.log stop working.

enter image description here

My sample Code App.js

const LOCATION_TRACKER = 'background-task-location';

export default class App extends Component {
     state = {
      mapRegion: null,
      hasLocationPermissions: false,
      locationResult: null,
      marker: {
        latitude: 0,
        longitude: 0
      },
      latitude: 0,
      longitude: 0,
      location: null,
      errorMessage: null
    }


   componentDidMount() {
    //this.watchCurLocation();
    this.onLoad();  

   }

   //init task manager
  onLoad = async() => {
    let isRegistered = await TaskManager.isTaskRegisteredAsync(LOCATION_TRACKER)
    if (!isRegistered) await Location.startLocationUpdatesAsync(LOCATION_TRACKER, {
      accuracy: Location.Accuracy.High,
      /* after edit */
      timeInterval: 2500,
      distanceInterval: 5,
    })
  }


onPress = async () => {
    console.log('waiting')
    await Location.startLocationUpdatesAsync(LOCATION_TRACKER, {
      accuracy: Location.Accuracy.High,
      timeInterval: 5000,
      distanceInterval: 5

    });

    console.log('waiting for get task option');
    //const data = await TaskManager.getTaskOptionsAsync(LOCATION_TRACKER)
    //console.log(data);

  };


watchCurLocation = () =>{
    this.onPress();
    setTimeout(() => {
      this.watchCurLocation();
    }, 5000);
  }


}


TaskManager.defineTask(LOCATION_TRACKER, ({ data, error }) => {
  if (error) {
    console.log(error)
    // Error occurred - check `error.message` for more details.
    return;
  }
  if (data) {
    const { locations } = data;
    console.log(data)
    // do something with the locations captured in the background
  }
});

Viewing all articles
Browse latest Browse all 29741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>