jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.09k stars 112 forks source link

Stuck at BackgroundTask: Job is running #56

Open vinaygosain opened 5 years ago

vinaygosain commented 5 years ago

For me the adb logcat is stuck at this message 09-06 20:59:47.398 5218 5300 D BackgroundTask: Initializing 09-06 20:59:47.419 5218 5218 D BackgroundTask: Setting foreground true 09-06 21:00:02.645 5218 5300 D BackgroundTask: @ReactMethod BackgroundTask.schedule 09-06 21:05:12.487 5218 5218 D BackgroundTask: Setting foreground false 09-06 21:05:12.487 5218 5218 D BackgroundTask: Committing job schedule 09-06 21:15:01.462 5218 5385 D BackgroundTask: Job is running

my code for background task

class BackgroundTasks { constructor() { const pushNotifications = new PushNotifications();

    BackgroundTask.define(() => {
        console.log('Hello from a background task');

        AsyncStorage.getItem('somekey').then((value) => {
           // do some work
            BackgroundTask.finish();
        });
    })
}

runBackgroundTask() {
    BackgroundTask.schedule();
    this.checkStatus();
}

async checkStatus() {
    const status = await BackgroundTask.statusAsync()
    console.log(status.available)
  }

}

and in my app.js

constructor(){ this.backgroundTasks = new BackgroundTasks(); }

componentDidMount() {
console.log('starting background service'); this.backgroundTasks.runBackgroundTask(); }

rishiankush commented 5 years ago

@vinaygosain

try to put the BackgroundTask.define() method out of the class and on the main index according to documentation.

check this out: https://github.com/jamesisaac/react-native-background-task#definetask

vinaygosain commented 5 years ago

yeah, i have tried that also, but it didn't work, apparently, this lib doesn't work for android version>8.0.0

scrimmie commented 4 years ago

Any updates on this issue because I am running into a very similar issue.

mttbrd commented 3 years ago

Same problem here, any updates?

hamdigatri commented 3 years ago

Same issue react native 0.61.5 Test on emulator Android 8.1.0