react-native-background-task icon indicating copy to clipboard operation
react-native-background-task copied to clipboard

Stuck at BackgroundTask: Job is running

Open vinaygosain opened this issue 6 years ago • 5 comments

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(); }

vinaygosain avatar Sep 06 '18 15:09 vinaygosain

@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

rishiankush avatar Sep 11 '18 10:09 rishiankush

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

vinaygosain avatar Sep 11 '18 14:09 vinaygosain

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

scrimmie avatar Aug 30 '19 01:08 scrimmie

Same problem here, any updates?

mttbrd avatar Sep 30 '20 02:09 mttbrd

Same issue react native 0.61.5 Test on emulator Android 8.1.0

hamdigatri avatar Oct 07 '20 22:10 hamdigatri