我希望在安卓手机上构建一个REST客户端。
这个REST服务器暴露了几个资源,例如(GET)
http://foo.bar/customer List of all customer
http://foo.bar/customer/4711 The customer with id 4711
http://foo.bar/customer/vip List of all VIP customer
http://foo.bar/company List of all companys
http://foo.bar/company/4711 The company with the ID 4711
http://foo.bar/company/vip List of all VIP companys
我(认为)我知道如何与REST服务器进行通信并获取所需的信息。 我将实现一个带有以下API的REST Client类
public List<Customer> getCustomers();
public Customer getCustomer(final String id);
public List<Customer> getVipCustomer();
public List<Company> getCompanies();
public Customer getCompany(final String id);
public List<Customer> getVipCompanies();
从Virgil Dobjanschi的演示“开发Android REST客户端应用程序”中,我了解到在Activity的Worker Thread中处理REST请求并不是一个好主意。相反,我应该使用Service API。
我喜欢有一个将绑定到(本地)服务的Singleton ServiceHelper的想法,但我担心我没有正确理解服务概念。
目前,我不明白如何将REST调用结果(在服务中异步完成)报告回调用活动。我也想知道是否需要一个处理所有REST请求(具有不同返回类型)的服务,还是是否需要一个专门的服务来处理每个REST请求。
可能我还有很多其他的理解问题,所以对我来说最好的事情是一个满足我的需求的样例应用程序。我的用例并不罕见,我希望那里有一个示例应用程序。
请告诉我吧!
任何其他指导我正确实现的建议都是有用的(Android API-Demo不符合我的用例)。
提前感谢。
Klaus 编辑:在发布此后在SO上发现类似的主题,这使我走向了我需要的方向(最小化复杂的“Dobjanschi模式”):