Expo Task Manager - Once a tasks starts am I unable to pass a changing state variable?

Please provide the following:

  1. SDK Version: 39
  2. Platforms(Android/iOS/web/all): Android

I am running task manager successfully through expo and react native, specifically collecting location data every 5 minutes. Essentially task manager checks every 5 minutes if you have entered a location and at the very beginning it gets passed a variable that checked if you were already within that location aka “checked in”. I’ve noticed that when I pass a state variable to task manager, once the task is running, it won’t accept a change in state. Is this the nature of a task that it cannot accept the change?

So for example below is a little pseudo code hopefully to get my question across:

App.js

import { configureBgTasks } from './MyTasks'
    ...
    state = {
    checkedin: false
    }
    ...
    
    runTasks = (...) = > {
    
    startLocationUpdates(....)
    
    }

...

checkThemIn = () => {
this.setState(checkedIn: true)
}
    
    
    ...
    
    checkdb = () = > {
       ...await fetch(....)
       if (your records are there) {
          this.setState({ checkedin: true })
       } else {
          this.setState({ checkedin: false })
       }
    
       //execute task manager function
       runTasks(checkedin, checkThemIn)
    }

    ...
    render() {
        console.log('APP.JS PAGE CHECKIN STATUS:', this.state.submitted);
    
        return (
    ...

MyTasks.js

 export const configureBgTasks = ({ checkedin, checkThemIn }) => {
    
      console.log('MY TASKS PAGE STATUS: ', checkedin)
     
     
      TaskManager.defineTask(TASK_FETCH_LOCATION, ({ data, error }) => {
      
        if (error) {
          // Error occurred - check `error.message` for more details.
          return;
        }
        if (data) {

        ...

        if(checkedin === false){ 

//FIRES TO CHANGE STATE IN APP.JS
checkThemIn()

}


    }
    })

What I have noticed is that the the checkThemIn function fires fine when a person enters a region and changes state in home, but then as task manager continues to fire and collect more location data the state remains false. So I end up with the following:

'APP.JS PAGE CHECKIN STATUS: true'
'MY TASKS PAGE STATUS: false'

Am I doing something wrong or is this the nature of TaskManager in that it cannot accept a state change once it runs?

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