Android Service and UI Thread

﹥>﹥吖頭↗ 提交于 2019-11-30 12:51:36
koti

Use IntentService instead of Service. If you do network calls in a Service, the UI will stuck. Therefore, use an IntentService since it uses a separate Thread.

And you do not know when a server message will retrieve the data. A NullPointerException could be thrown if objects are accessed as long as network calls are still in progress. Use BroadcastReceivers to fire an Intent whenever a server responds.

R4j

As far I know, Android service run on UI thread. If you want to make an asynchronous job, you should use Intent Service
See: What is the difference between an IntentService and a Service?
Here is an Intent service example you can try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!