应用程序在后台运行时不执行异步代码

时间:2018-08-09 14:10:36

标签: android react-native android-jobscheduler

使用react-native-background-fetch可以强制jobscheduleradb shell cmd jobscheduler run -f <your.application.id> 999一起运行,当我的应用在后台运行时。

这将执行所有同步代码,但直到再次打开应用程序后,才会执行调用堆栈中放置的所有内容(例如async,promise或setTimeout)。在iOS上一切正常。

BackgroundFetch.configure({
  minimumFetchInterval: 15, // minutes (15 is minimum allowed)
  stopOnTerminate: false,   // Android-only,
  startOnBoot: true         // Android-only
}, () => {
  console.log('Start background fetch') // Log happens

  setTimeout(() => {
    console.log('In timer!') // Log does not happen until app is opened
  }, 1000)
}, (error) => {
  console.error('[js] RNBackgroundFetch failed to start', error)
})

我如何在Android的后台运行异步代码,我是否缺少某些设置或配置?

0 个答案:

没有答案