Android: keep the web server running

I'm running a web server (nanohttpd) in an Android service

Onstartcommand() returns a value from the method overridden in the service, so it should be "sticky"

However, the service seems to have stopped, or at least the web server has stopped responding. Most of the time, it occurs when the device is inactive after the screen is turned off for a period of time. However, sometimes it seems to be running normally. The notification icon of the service is always displayed

The device does not perform any other operations and is powered on

How do I make the web server respond to requests? Or at least reduce the frequency of power outages?

resolvent:

In your case, the best chance will not be killed by the system:

>Start the service before startforegroup > prompt your users to include your application in the ignore battery optimization list (you cannot do this programmatically):

Intention = new intention (settings. Action_ignore_battery_optimization_settings); startActivity(intent);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>