凡保留改造适配器的Andr​​oid应用程序? [英] Where to keep Retrofit Adapter in Android App?

查看:119
本文介绍了凡保留改造适配器的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚在哪里Refrofit适配器和API类应保持在Android的?我应该使用应用程序类或辛格尔顿保持适配器?怎么样的API接口类?

I am not clear on where Refrofit adapter and API classes should be kept in Android? Should I use Application class or Singleton to keep the adapter? How about the API interface classes?

  RestAdapter myRestAdapter;   // where should I keep this guy?

 MyAPI mApi = myRestAdapter.create(MyAPI.class);  // and how about this guy?

我有几个不同的API像MyApi1,MyApi2,即得到所谓的内部片段在应用程序的不同点。

I have a few different api like MyApi1, MyApi2, that get called inside fragments at different points in app.

感谢

推荐答案

这两个应被视为单身,只创造了一次。

Both of these should be treated as singletons and only created once.

RestAdapter 保存常见的请求执行人,共享HTTP客户端配置,远程服务信息等,这些应该为每个API接口共享。

The RestAdapter holds the common request executor, shared HTTP client configuration, remote service info, etc. These should be shared for every API interface.

该API接口也应该单身。它们都是线程安全,并需要一个位初始化处理时创建(最小的,但不为零)。

The API interfaces should also be singletons. They are thread safe and require a bit of initial processing when created (minimal, but non-zero).

这篇关于凡保留改造适配器的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆