vikeri / react-native-background-job

Schedule background jobs in React Native that run your JavaScript when your app is in the background/killed.
MIT License
747 stars 109 forks source link

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

Closed txcyy closed 4 years ago

txcyy commented 4 years ago
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 4 years ago

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

wy10 commented 3 years ago

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