简体   繁体   English

为什么要使用Android本地服务执行后台联网任务?

[英]Why would I use an Android local service for a background networking task?

I am writing an Android application which establishes a "semi-permanent" TCP socket connection, ie the connection should always be established when the application is visible but can be closed when it is not visible. 我正在编写一个可建立“半永久” TCP套接字连接的Android应用程序,即,应始终在可见应用程序时建立连接,但在不可见时可以关闭连接。

Currently, the connection is handled in a thread. 当前,连接是在线程中处理的。 The connection is only needed in one activity. 仅在一项活动中需要连接。

I am wondering what would be the advantages of putting the networking thread into an Android local service. 我想知道将网络线程放入Android本地服务的优势是什么。

如果在不可见应用程序时不需要在后台从连接中获取数据,那么插入服务中没有任何好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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