我不清楚在哪里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).
相关推荐
最新文章