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

Not working on Android

Open shammus672agmailcom opened this issue 8 years ago • 10 comments

I am using this library for background work but not working.... This part seams no response ...(no error but not working )

BackgroundTask.define(async () => { // Fetch some data over the network which we want the user to have an up-to- // date copy of, even if they have no network when using the app const response = await fetch('http://feeds.bbci.co.uk/news/rss.xml') const text = await response.text()

// Data persisted to AsyncStorage can later be accessed by the foreground app await AsyncStorage.setItem('@MyApp:key', text)

shammus672agmailcom avatar Aug 10 '17 08:08 shammus672agmailcom

Please try running the following command:

$ adb logcat *:S ReactNative:V ReactNativeJS:V BackgroundTask:V

And paste your logs here (if it doesn't provide you enough of a clue to tell what's going on).

Keep in mind that after the app leaves the foreground, you'll have to wait at least 50% of the desired period (so, default is 7m30s) before the task executes.

jamesisaac avatar Aug 10 '17 10:08 jamesisaac

Hey, I m getting the following error while i m executing the package undefined is not an object (evaluating 'RNBackgroundTask.schedule')

48memory avatar Sep 14 '17 09:09 48memory

@48memory Then the Android library probably wasn't linked correctly. Make sure these changes were made by the react-native link command: https://github.com/jamesisaac/RNBackgroundTaskExample/commit/718b3d2cfe1fa1a649ddb285be921ad8974dff26

jamesisaac avatar Oct 13 '17 18:10 jamesisaac

Is there a way to test this without having to wait? Similar to how Xcode provides Debug > Simulate background fetch. I was thinking of calling AppRegistry.startHeadlessTask when the app goes to background, but no dice.

sampurcell93 avatar Nov 22 '17 19:11 sampurcell93

I am also facing same issue please help me out, I am using this library for background work but not working.... This part seams no response ...(no error but not working )

BackgroundTask.define(async () => { // Fetch some data over the network which we want the user to have an up-to- // date copy of, even if they have no network when using the app this.test().done(); BackgroundTask.finish() }) test = async() =>{ console.log('Hello from a background task11'); // Data persisted to AsyncStorage can later be accessed by the foreground app let s = await AsyncStorage.setItem('done','hello'); //alert(JSON.stringify(s)); }

sandeepkandra avatar Apr 04 '18 17:04 sandeepkandra

I think it is a bug and the async task should be await . At the path of react-native-background-task/js/index.android.js. I changed the code define: function(task) { // Register the headless task const fn = async () => { task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }

to

define: function(task) { // Register the headless task const fn = async () => { await task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }

In my case, it worked. Hope it helps.

kent426 avatar Jun 26 '18 12:06 kent426

thank you.

On Tue, 26 Jun 2018, 17:46 Kent Huang, [email protected] wrote:

I think it is a bug and the async task should be await . At the path of react-native-background-task/js/index.android.js. I changed the code

define: function(task) { // Register the headless task const fn = async () => { task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }

to

define: function(task) { // Register the headless task const fn = async () => { await task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }

In my case, it worked. Hope it helps.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jamesisaac/react-native-background-task/issues/8#issuecomment-400286013, or mute the thread https://github.com/notifications/unsubscribe-auth/AL2zR0yley5hCFzoikUDklj7M43AmeDDks5uAiYBgaJpZM4OzFz3 .

sandeepkandra avatar Jun 26 '18 12:06 sandeepkandra

@kent426 I have the same issue and I did what you say to do and it still doesn't working :( Is there any other solution?

oron11 avatar Jul 26 '18 10:07 oron11

@oron11 I am not sure about your specific problem but, as the library described, you have to wait at least like 10 mins after you put your app into background, for the background task getting executed. Maybe u can elaborate on your problem a bit.

kent426 avatar Aug 07 '18 15:08 kent426

Hi, i am stuck with this issue , it logs in adb logs "job is running" but i didn't get any logs for job defined function ? can anyone help?

Narsinhs avatar Mar 20 '21 01:03 Narsinhs