I am running a web server (NanoHTTPD) in an Android Service.
onStartCommand() returns the value from the overridden method in Service, so it should be "sticky".
However the service seems to stop, or at least the webserver stops responding. This happens mostly when the device has been inactive for a while, with the screen off. But also sometimes when it is seemingly running normally. The notification icon of the service keeps being displayed.
The device is not doing anything else, and it is plugged into power.
What can be done to keep the web server responding to requests? Or at least reduce the frequency of outages?
The best chances not being killed by the system in your case:
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(intent);
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