vikeri/react-native-background-job

react-native-background-job doesnt work on Android 9.0

Closed this issue · 2 comments

txcyy commented
App.js
import BackgroundJob from 'react-native-background-job';

const backgroundJob = {
  jobKey: "headlessJob",
  job: ()=>{
    console.log('run job');
    
    // setInterval(()=>{
    //   console.log('job')
    // },3000)
  }
 };
  
 BackgroundJob.register(backgroundJob);

const App = () => {
  useEffect(() => {
    BackgroundJob.schedule({
      jobKey: "headlessJob",
      // allowExecutionInForeground:true,
      period:5000,
      exact:true
    }).then(() => console.log("job started"))
    .catch(err => console.err(err));
  }, []);
}

run app, and log 'job started', then I change the app status to background , about 5 seconds later, the app crashed.
Did I do anything wrong?

txcyy commented

solved the problem by add permission <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

wy10 commented

but i test my app,I change the app status to background it works few times,my function is no longer executed