react-native-background-actions
react-native-background-actions copied to clipboard
[TypeError: Cannot read property 'start' of null] Did anyone got this for the first time?
I'm using the latest "react-native-background-actions": "^4.0.1", trying to understand why am I getting null when I do await BackgroundService.start(veryIntensiveTask, options); So did anyone experience this issue before? Please see package.json and sample code which I used
Package.json
{
"name": "trackingproject",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
},
"dependencies": {
"@dangttp/react-native-background-service": "^0.1.3",
"@microsoft/signalr": "^8.0.0",
"@react-native-async-storage/async-storage": "1.23.01",
"@react-native-community/geolocation": "^3.2.1",
"@react-native-community/hooks": "^3.0.0",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.9.17",
"axios": "^1.6.7",
"expo": "~51.0.31",
"expo-camera": "~15.0.15",
"expo-file-system": "~17.0.1",
"expo-location": "^17.0.1",
"expo-sharing": "^12.0.1",
"expo-status-bar": "~1.12.1",
"expo-task-manager": "~11.8.2",
"expo-updates": "~0.25.24",
"haversine-distance": "^1.2.3",
"moment": "^2.30.1",
"node-signalr": "^3.0.0-alpha.1",
"react": "18.2.0",
"react-native": "0.74.5",
"react-native-background-actions": "^4.0.1",
"react-native-bouncy-checkbox": "^3.0.7",
"react-native-get-random-values": "~1.11.0",
"react-native-maps": "1.18.0",
"react-native-maps-directions": "^1.9.0",
"react-native-maps-routes": "^1.0.3",
"react-native-modal": "^13.0.1",
"react-native-pager-view": "6.3.0",
"react-native-reanimated": "^3.15.4",
"react-native-tab-view": "^3.5.2",
"react-native-url-polyfill": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@tsconfig/react-native": "^3.0.2",
"@types/jest": "^29.5.11",
"@types/react": "~18.2.79",
"@types/react-native": "^0.73.0",
"@types/react-test-renderer": "^18.0.7",
"typescript": "^5.3.3"
},
"private": true
}
sampleCode.tsx
import * as React from 'react';
import { Text, View} from 'react-native';
import BackgroundService from 'react-native-background-actions';
import { useEffect } from 'react';
const veryIntensiveTask = async (taskDataArguments: any) => {
console.log('Yahhhhhhhhhhhhhh');
};
const options = {
taskName: 'Example',
taskTitle: 'ExampleTask title',
taskDesc: 'ExampleTask description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
linkingURI: 'yourSchemeHere://chat/jane', // See Deep Linking for more info
parameters: {
delay: 1000,
},
};
export function IntroScreen({ navigation }: any) {
const startBackgroundTasks = async () => {
try {
if (BackgroundService) {
await BackgroundService.start(veryIntensiveTask, options); // I believe here where its failing
await BackgroundService.updateNotification({
taskDesc: 'New ExampleTask description',
});
}
} catch (error) {
console.error(error);
}
};
useEffect(() => {
console.log('Yaaag');
startBackgroundTasks();
}, []);
return (
<View>
<Text>Bavckground Service System</Text>
</View>
);
}
Any suggestions or feedback would be appreciated :)
Any fix for this?
Nope still waiting..
I got the same error. I just runned gradlew clean inside android folder and reinstalled the App
Any fix for this?
just re-build the app, it works for me