开发者

call multiple methods of local services

开发者 https://www.devze.com 2023-04-11 04:07 出处:网络
I want to create an app wich connects to one server with an https connection from different activities. So I thought, it would make sense to use a service which holds the https connection and i would

I want to create an app wich connects to one server with an https connection from different activities. So I thought, it would make sense to use a service which holds the https connection and i would call it from different activities to get different sites from that server... But after searching a long time (and reading an android book) I didn't find out, how to call different methods of a service from an activity. (only way that seemed 开发者_如何学Gopossible was aidl with .asInterface, but that never worked for me, as one can see in my other question) Is there a good tutorial, how I can do this? Thanks in advance, Tyde


The way I would do this is to have one package that does the http calls, internally it may use HTTPUrlConnection or AndroidHTTPClient, and throughout the codebase I will just call the helper methods (which I will write, basically wrapper methods) of this class/package to make the calls. Note that for me the http connections are either handled as subclasses of DataHandler to be run on seperate threads, or as async tasks, the point being we dont lock the main UI thread with it.

On a side note look at this blog post too. Android developer blog have good posts on this topic.

I havent seen http calls managed by a service, the Async task/Data Handler mechanism seems more simpler to me. Hope this helps.

0

精彩评论

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

关注公众号