开发者

How to consume SOAP/REST web services on Android (Service/Broadcast/Intent/etc)

开发者 https://www.devze.com 2023-03-28 05:49 出处:网络
Is there a comm开发者_开发百科on way to consume web services from Android applications (aside from the protocol)? What I need is a Service or Intent or Thread (or anything else) that is capable of:

Is there a comm开发者_开发百科on way to consume web services from Android applications (aside from the protocol)? What I need is a Service or Intent or Thread (or anything else) that is capable of:

  1. staying alive no matter what Activities are open;
  2. be able to perform multiple requests at the same time;
  3. accept input values and return output values to the right caller;
  4. be able to discard an ongoing operation (while keeping to run all the others) and not to return the output value if it is no longer desired;
  5. (of course) run asynchronously.

Is there a common way to accomplish this? I've had some issues while using Services, primarily because I wasn't able to discard an ongoing operation, so the results were colliding with each other.


You should use Service for this task. This is the only component that was designed to handle background long-running tasks. Most likely you need to use this service as a "locally bound" to pass complex requests and responses without need for serialization, and to perform other tasks that are relatively hard to implement via Intents.

Read more about locally bound services here: Bound Services.


mmm you need a combination of things here. First of all, you need a service layer implement it with a Bound Service (inherits). Your UI activities must call this service through an Intent. Then, this layer that would be execute it in a different thread than your UI layer, must have a Rest Client object to perform services calls. Here you have lot of approaches, I recommend you Spring Rest implementation as well as Restlet.

As is a pretty big discussion, anything else please tell me.

0

精彩评论

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

关注公众号