react-native-boundary: Headless event listener not called when app is killed
Hey @eddieowens !
When the app is in foreground or background the boundary callbacks work perfectly!
But I am struggling with the Headless part when the app is killed.
In logcat I can see that the event is fired. I see the log message from boundary’s index.js file:
ReactNativeJS: 'onExit', [ 'rated0' ]
which comes from this part of code here:
const HeadlessBoundaryEventTask = async ({event, ids}) => {
console.log(event, ids);
boundaryEventEmitter.emit(event, ids)
};
But my callback is never executed. I think the issue might be timing. When the app starts because of a Headless event I can see that boundary receives the event as said above. I added log messages for the Callback Registration and it seems to happen after the Headless event:
15:03:19.837 ReactNativeJS: 'onExit', [ 'rated0' ] // from boundary's index.js
15:03:19.863 ReactNativeJS: Registering Boundary Callbacks // my code
I moved the callback registration to the very first line of my index.js but the order still seems to be incorrect. Any idea how to solve this? Where should I call the Boundary.on callback registration in my code?
Setup:
- “react-native”: “0.59.5”
- “react-native-activity-recognition”: “woffu/react-native-boundary” // fix for newer android versions
Help is very much appreciated 😃
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 24
@NuclearKev I am working on a fix for iOS, should come very shortly.
@SufniDroid just like how react-native-boundary does it:
So in our case:
EDIT: or like this if you don’t want to have a named function:
@mathiasmoeller I was having the same issue and fixed it by registering another headless task in
index.jsfor the event. Then I just have it run the same code as it normally would. This method doesn’t work for iOS, however, so it’s not a great solution. I can’t get iOS to do stuff when the app is killed and I don’t know why.