Android: web server support

I am using a web server (NanoHTTPD) on an android service.

onStartCommand () returns the value from the overridden method in Service, so it should be sticky.

However, the service appears to be stopping, or at least the web server stops responding. This happens mainly when the device is inactive for a while, with the screen off. But also sometimes when it seems to be working fine. The service notification icon continues to be displayed.

The device is doing nothing, and it is connected to the network.

What can be done to make the web server respond to requests? Or at least reduce the frequency of outages?

+3


source to share


1 answer


The best chances of not being killed by the system in your case are:



  • Start the startForeground service
  • Ask your users to include your application in the "ignore batteries" list (you cannot do this programmatically): Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); startActivity(intent);

+2


source







All Articles