简体   繁体   中英

How to keep service running in background in Android O?

I need to keep a service running in background. This service is used to keep a Socket.IO/MQTT connection. In versions previous to Android O there were no problem keeping the service alive, but in Android O this is not possible because of the background execution limits .

Is there any way to keep the services running, besides foreground service?

You should use Firebase Cloud Messaging to push data from a server, this is to prevent all apps opening their own connection and staying active, draining the battery and filling up the RAM for no value to the user. Your app should be no exception to that.

For short lived connections (minutes), or user sessions (minutes, too, unless the user stays active longer), a foreground service might be a solution.

Out of curiosity, what is your use case for wanting a "persistent connection"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM