This PR finally implements a Go backend integration into an Android foreground service. Long story short, it allows running networking Go code in the background indefinitely, without murdering it along with the app. :tada:
If anyone's following my path, to run a Go process in Android, you need to:
Request the FOREGROUND_SERVICE permission for your application (since only foreground services are allowed to stay alive indefinitely).
Create a class that implements Service and register it in your Android manifest (so that the OS can launch it and track it as such, it needs to be aware of the special snowflake thread/process).
In your UI activity (or wherever), launch with it startForegroundService.
In your services's start method, set up a system notification (Android will kill your service unless you show the user that it exists).
On newer Android's you also need an explicit notification channel (tech detail, not sure why)
Tell Android to pin your service to the foreground startForeground (you have 5 seconds to reach this point from startForegroundService mind you).
Voila, do whatever you want, it will stay alive (I think/hope)
Just as a memo, even if your app is React Native, there's no getting around writing native Java code for this. The notification system is an integral part of Android and to set it up + run your own native code, RN is just a useless obstacle. Suck it up and jump into Java.
This PR finally implements a Go backend integration into an Android foreground service. Long story short, it allows running networking Go code in the background indefinitely, without murdering it along with the app. :tada:
If anyone's following my path, to run a Go process in Android, you need to:
FOREGROUND_SERVICE
permission for your application (since only foreground services are allowed to stay alive indefinitely).Service
and register it in your Android manifest (so that the OS can launch it and track it as such, it needs to be aware of the special snowflake thread/process).startForegroundService
.startForeground
(you have 5 seconds to reach this point fromstartForegroundService
mind you).Just as a memo, even if your app is React Native, there's no getting around writing native Java code for this. The notification system is an integral part of Android and to set it up + run your own native code, RN is just a useless obstacle. Suck it up and jump into Java.
Fixes https://github.com/coronanet/rn-coronanet/issues/3