Where to keep the retrofit adapter in an Android application?
source link: https://www.codesd.com/item/where-to-keep-the-retrofit-adapter-in-an-android-application.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Where to keep the retrofit adapter in an Android application?
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?
I have a few different api like MyApi1, MyApi2, that get called inside fragments at different points in app.
Thanks
Both of these should be treated as singletons and only created once.
The RestAdapter
holds the common request executor, shared HTTP client configuration, remote service info, etc. These should be shared for every API interface.
The API interfaces should also be singletons. They are thread safe and require a bit of initial processing when created (minimal, but non-zero).
Related Articles
I get the same name from the list where I keep the for loop in listview
Is there a way to programmatically detect the UI components of an Android application?
In DDD where to keep the custom exceptions (application exceptions)? In the Infrastructure layer?
Where to keep the log files for the WAR application?
Where to keep the .plist file in the iphone app
Android - where to keep the global data?
How to highlight a ListView item using OnLongClickListener from the custom adapter class in Android
How to keep the WakeLock as long as an application is open / running?
Call the Worklight Adapter from an external application
How to convert a bitmap view and keep the same item size in Android?
How can I keep the size of a small Delphi application when it has a lot of TImage components?
How to use the OSM card in an Android application? Is there a tutorial to learn how to use OSM in Android?
How do I ask the user to install another Android application (including my app), during my application installation?
How to see all the threads generated by an Android application
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK