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:
- staying alive no matter what Activities are open;
- be able to perform multiple requests at the same time;
- accept input values and return output values to the right caller;
- 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;
- (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 Intent
s.
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.
精彩评论