开发者

should we use services for network connections in android

开发者 https://www.devze.com 2023-01-01 14:28 出处:网络
should we use android services for netw开发者_JS百科ork connection? if yes please provide me a sample.It depends what kind of network connection you are using. If you just want to fetch some data from

should we use android services for netw开发者_JS百科ork connection? if yes please provide me a sample.


It depends what kind of network connection you are using. If you just want to fetch some data from the web I would recommend using a AsyncTask. If you are opening a port to a distant server for a longer living connection like a chat application would use you may want to look at a service.


In general you're better of just wraping the communication in an AsyncTask. Then you can easily handle for instance progress updates and canceling of requests etc. Services should be reserved for heavy lifting.

0

精彩评论

暂无评论...
验证码 换一张
取 消