在Android App中将Retrofit Adapter保留在哪里?

在Android App中将Retrofit Adapter保留在哪里?,第1张

概述我不清楚在Android中应将Refrofit适配器和API类保留在何处?我应该使用Application类还是Singleton来保留适配器?API接口类怎么样?RestAdaptermyRestAdapter;//whereshouldIkeepthisguy?MyAPImApi=myRestAdapter.create(MyAPI.class);//andhowaboutthisguy

我不清楚在Android中应将Refrofit适配器和API类保留在何处?我应该使用Application类还是Singleton来保留适配器? API接口类怎么样?

  RestAdapter myRestAdapter;   // where should I keep this guy? MyAPI mAPI = myRestAdapter.create(MyAPI.class);  // and how about this guy?

我有一些不同的API,例如MyAPI1,MyAPI2,它们在应用程序中的不同位置的片段内部被调用.

谢谢

解决方法:

这两个都应视为单例,并且只能创建一次.

RestAdapter包含公共请求执行程序,共享的http客户端配置,远程服务信息等.这些应该为每个API接口共享.

API接口也应该是单例.它们是线程安全的,并且在创建时需要一些初始处理(最小,但非零).

总结

以上是内存溢出为你收集整理的在Android App中将Retrofit Adapter保留在哪里?全部内容,希望文章能够帮你解决在Android App中将Retrofit Adapter保留在哪里?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1095770.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存