Open bajrangsharma-burrp opened 5 years ago
waiting for nice update...
Try the latest version 2.2.0
Thanks for the update...Sure will try...
Updated 2.2.0 ("react-native-background-job": "^2.2.0") but still same issue...
Can you show me your code?
Code implementation as below:
const backgroundJob = {
jobKey: "myJob",
job: () => {
locat();
}
};
BackgroundJob.register(backgroundJob);
var backgroundSchedule = {
jobKey: "myJob",
period: 2000,
allowWhileIdle: true,
exact: true,
requiresCharging: true,
requiresDeviceIdle: true,
override: false,
timeout: 3000,
allowExecutionInForeground: true,
networkType: BackgroundJob.NETWORK_TYPE_ANY
}
BackgroundJob.schedule(backgroundSchedule);
BackgroundJob.isAppIgnoringBatteryOptimization((error,ignoringOptimization) => {
console.log(error+' <<Android>>ignore>> '+ignoringOptimization)
});
const locat = async (data) => {
navigator.geolocation.getCurrentPosition((position) => {
console.log('Android>>: Location>>222--->>: '+JSON.stringify(position.coords));
});
Could you try with a function that is not async and try with only the required options to see if that works
Try but same issue. Close app by swipe then nothing is running in background. How can be achieve this goal???...
Can I see the updated code that you tried?
const locat = (data) => {
navigator.geolocation.getCurrentPosition((position) => {
console.log('Android>>: Location>>222--->>: '+JSON.stringify(position.coords));
});
removed async. Working fine when app in Foreground and Background(not kill/close)...
Any hope for the same implementation logic...
Try these settings instead
var backgroundSchedule = {
jobKey: "myJob",
period: 2000,
exact: true,
allowExecutionInForeground: true,
}
Also, be aware that it can take a long while before the apps starts up again depending on when Android lets your app start up.
Sure will try the same...
Its working but not all devices...Don`t know why?.
Working on Samsung after kill/close the app but not working on OPPO.
Is there any specific reason?.
I think OPPO device OS could be customised so not allowed any background services...Don`t know m correct or wrong.
If u have any clarification Plz share with me...
Yesterday this logic working fine on Android version 8.0(Oreo) but today not working on kill/close.
This scenario is so strange still don`t understand...In which case this is working and in which case this is not working on Oreo and why?.
Let me know behind of this actually what happened?...
does not work with galaxy s7. After killing the app the job does not execute. Scheduling push notification works with this libaray https://github.com/zo0r/react-native-push-notification, but there is no event when the push notification shows. In this Libary they use the Alarm Manager.
hi,
After new install "react-native-background-job" getting error:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/graphics/drawable/DrawableWrapper.class
Re-install...cache clean...delete build folder did everything but issue present.
Plz let me something why this happened?...
Any hope for Android Oreo OS...
Hi,
This logic working on all devices with Oreo(Android OS v8.0+) but not working on OPPO(7.1.1) device after kill/close but at Samsung(7.1.1) working fine.
Wts going behind of these Plz let me and why this happened...
This works in app closed/background/foreground
import React, {Component} from 'react';
import {Platform, TouchableOpacity, Text, View} from 'react-native';
import BackgroundJob from 'react-native-background-job';
import axios from "axios";
const backgroundJob = {
jobKey: "myJob",
job: async () => {
try{
let res = await axios.get("https://jsonplaceholder.typicode.com/posts/42")
console.log(res.data)
}catch(e){
console.log(e);
}
}
};
BackgroundJob.register(backgroundJob);
export default function App(){
const startJob = () => {
BackgroundJob.schedule({
jobKey: "myJob",
period: 5000,
exact: true,
allowExecutionInForeground: true,
});
}
return (
<View style={{flex:1}}>
<TouchableOpacity onPress={startJob}>
<Text>Start</Text>
</TouchableOpacity>
</View>
);
}
@abtuhin it works for 15 minutes of inactivity, but after that it stops. I removed the app from the battery optimisation settings but still the same. Any ideas?
Use this to check weather battery optimization is enabled ?
https://www.npmjs.com/package/react-native-disable-battery-optimizations-android
This works in app closed/background/foreground
import React, {Component} from 'react'; import {Platform, TouchableOpacity, Text, View} from 'react-native'; import BackgroundJob from 'react-native-background-job'; import axios from "axios"; const backgroundJob = { jobKey: "myJob", job: async () => { try{ let res = await axios.get("https://jsonplaceholder.typicode.com/posts/42") console.log(res.data) }catch(e){ console.log(e); } } }; BackgroundJob.register(backgroundJob); export default function App(){ const startJob = () => { BackgroundJob.schedule({ jobKey: "myJob", period: 5000, exact: true, allowExecutionInForeground: true, }); } return ( <View style={{flex:1}}> <TouchableOpacity onPress={startJob}> <Text>Start</Text> </TouchableOpacity> </View> ); } `the same way i used background service after app killing and sleeping mode background service worked android version 6 but the same way not worked android version 9
This works in app closed/background/foreground
import React, {Component} from 'react'; import {Platform, TouchableOpacity, Text, View} from 'react-native'; import BackgroundJob from 'react-native-background-job'; import axios from "axios"; const backgroundJob = { jobKey: "myJob", job: async () => { try{ let res = await axios.get("https://jsonplaceholder.typicode.com/posts/42") console.log(res.data) }catch(e){ console.log(e); } } }; BackgroundJob.register(backgroundJob); export default function App(){ const startJob = () => { BackgroundJob.schedule({ jobKey: "myJob", period: 5000, exact: true, allowExecutionInForeground: true, }); } return ( <View style={{flex:1}}> <TouchableOpacity onPress={startJob}> <Text>Start</Text> </TouchableOpacity> </View> ); }
This is not a code reason, you know? This is the reason for different devices and Android systems.
Hello All, Can I define my job with some parameters?
const backgroundJob = {
jobKey: "myJob",
job: async (parameter) => {
//logic using parameter
}
};
This works in app closed/background/foreground
import React, {Component} from 'react'; import {Platform, TouchableOpacity, Text, View} from 'react-native'; import BackgroundJob from 'react-native-background-job'; import axios from "axios"; const backgroundJob = { jobKey: "myJob", job: async () => { try{ let res = await axios.get("https://jsonplaceholder.typicode.com/posts/42") console.log(res.data) }catch(e){ console.log(e); } } }; BackgroundJob.register(backgroundJob); export default function App(){ const startJob = () => { BackgroundJob.schedule({ jobKey: "myJob", period: 5000, exact: true, allowExecutionInForeground: true, }); } return ( <View style={{flex:1}}> <TouchableOpacity onPress={startJob}> <Text>Start</Text> </TouchableOpacity> </View> ); }
yes its working when application running in background/foreground . but when application is killed or closed its not working ..
Issue Description
Unable to run background job even app is closed
Steps to Reproduce / Code Snippets / Screenshots
1> Launch the app, 2> Do some activities, 3> Kill/Close the app by swipe
Environment
React Native version: "react-native": "0.52.0", "react-native-background-job": "^2.1.1",
Platform(s) (iOS, Android, or both?):
Android
Device info (Simulator/Device? OS version? Debug/Release?):
Device-7.1.1-Debug