REST API客户端库为Android客户端、REST、API、Android

2023-09-13 02:24:17 作者:还有我疼你へ

我们正在建立一个基于位置的消息应用程序,它使用Parse.com作为后端 (Parse.com类似于城市飞艇/ PubNub等),我们现在要切换到我们自己的后端进行更好的控制。为此,我们已经建立了一个基于Node.js的后端与功能暴露在REST API

We are building a location based messaging app which uses Parse.com as back-end (Parse.com is similar to Urban Airship/PubNub, etc) and we now want to switch to our own back-end for better control. For this, we have built a node.js based back-end with functionality exposed over REST API

要消耗这个API,我们要建立一个Android库(类似于 Parse.com的Andr​​oid SDK )的抽象所有的HTTP请求/响应或REST API调用,可直接作用于各种操作,如getUsers(),那么SendMessage()等

To consume this API, we want to build an Android library (similar to Parse.com's Android SDK) which abstracts all the HTTP Requests/Response or REST API calls and provides direct functions for various operations like getUsers(), sendMessage(), etc

的方式来实现的REST API客户端在Android的:

使用IntentService + ResultReceiver 服务 的AsyncTask 使用Loaders Using IntentService + ResultReceiver Service AsyncTask Using Loaders

现在,考虑到​​我们想要建立一个Android库,并有可能是同时的REST API调用在用户与应用程序交互,哪种方法将是最好的与前进?我接受其他的建议/建议为好。

Now, considering that we want to build an android library and there could be simultaneous REST API calls while the user is interacting with the app, which approach would be the best to go ahead with ? I am open to other suggestions / recommendations as well.

更新:首先,我们建立了我们自己的图书馆使用IntentService + ResultReceiver它工作得很好。但是,我们后来在整个的Andr​​oid异步的Http 栽了跟头。用它。这是真棒!

UPDATE: We first built our own library using IntentService + ResultReceiver which worked fine. But we later stumbled across Android Async Http. Use it. It's awesome!

推荐答案

最好的执行力度基于谷歌IO PRO提示我已经看到2010年是RoboSpice库,它是基于REST的,非常巧妙的工作与活动的生命周期,以不漏内存。

Best implimentation I have seen based on Google IO Pro Tips 2010 is the RoboSpice library, which is REST based and very cleverly works with the Activity lifecycle as to not leak memory.

快速infographic图书馆是这里

Quick infographic the library is here

在装载机设计用于数据库,没有休息,他们正在重置活动复位这意味着你失去你的数据。 异步任务,只是没有。 意图服务+接收器的结果基本上是RoboSpice是如何工作的,因此,如果您正在构建自己的LIB,我会采取这种方法! 服务也不错,类似IntentService方法,但IntentService工作在这种情况下更好一点。

服务方法也许更好,look在robospice服务的,他们使用的ExecutorService 这会终止服务时,它已经运行了要求工作,通过,这是更多的Java并发比Android特有的。主要是要注意的是,服务运行,而在处理请求然后终止其自身,如果他们都没有留下。

The Service method maybe better, look at the robospice service they use an ExecutorService which terminates the Service when it has run out of Requests to work through, this is more Java concurrency than Android specific. Main thing to note that the service runs whilst processing requests then terminates its self if their are none left.

使用的ExecutorService 或任何类型的线程池的好处是,你可以定义多少可以请求同时运行。除非你有一个非常快速的连接2-4是最让我将永远建议。

The advantage of using the ExecutorService or any type of thread pool, is that you can define how many requests you can run at once. unless you have a very fast connection 2-4 is the most i would ever suggest.