开发者

Thread in a Service or Service in a Thread?

I'm writing an application for Android that retrieve data from th开发者_如何学运维e web and reformat it for the user. The user specify some input data, HttpClient connect to the site, and return objects representing the data asked by the user.

The network part is obviously too slow to be runt in the main thread, so I thought about splitting it in a different thread, maybe as a Service. So I have a design question:

1) Should I start a new HttpClient for each request in a new thread, or should I build a Service which deals with Http and return the data, to be runt in a separate thread?

2) Which is the easiest way to communicate between thread or activities for an application like mine?

Cheers


An AsyncTask would be a better choice. That way you could update the UI with a progress bar from within your call.

Details at http://developer.android.com/reference/android/os/AsyncTask.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜