I am trying to figure out how to run background service in react native (Android). Is it possible to run code (e.g. socket listener) while app is running in background or not. I created something simple to determine that, but seems like it's not working that way. Any help?
class HolaProject extends React.Component {
constructor(props) {
super(props);
this.state = {holaText: "0"};
var self = this;
setTimeout(() => {
self.setState({holaText: "after 10 seconds, works!"})
}, 10000);
}
render() {
return (
<DrawerLayoutAndroid renderNavigationView={() => <Text>React Native</Text>}>
<Text>{this.state.holaText}</Text>
<ProgressBarAndroid />
</DrawerLayoutAndroid>
);
}
};
On Android
Yes, it can be done. Check this link for more information. Basically, you have to enable a notification to "wake" the device when receiving information.
On iOS
Yes, it can be done too, but through hacks. Check these links on SO to have a deeper understanding of these hacks
Play a silent sound and set the background mode to audio. Check this answer for more information on the matter.
Use VoIP services. Check more here but it'll require you justify a VoIP service to Apple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With