8

Where to keep the retrofit adapter in an Android application?

 2 years ago
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.
neoserver,ios ssh client

Where to keep the retrofit adapter in an Android application?

advertisements

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

//i want to display list items in list view i am put all the items in list i want to display all the items in listview it is displaying but getting same names where i keep the for loop in getview.Please help me how can i pshow the list items in listv

Is there a way to programmatically detect the UI components of an Android application?

I want to take the source, or preferably just the .apk file, and find out all the UI components of an Android application (ex. XML layout). Is there any way to accomplish this task? Thanks.You can use apktool or APK Manager (that uses apktool) for re

In DDD where to keep the custom exceptions (application exceptions)? In the Infrastructure layer?

I'm building a app with following architecture: UI - Application - Domain - Infrastructure I have a Application Layer that need use custom exceptions. Where I keep these custom exceptions? In Infrastructure layer? The problem is my Application Layer

Where to keep the log files for the WAR application?

I'm trying to configure logging for my web application (WAR), in log4j.properties: log4j.rootCategory=WARN, RF log4j.appender.RF=org.apache.log4j.RollingFileAppender log4j.appender.RF.File=???/my-app.log What file path I should specify for my-app.log

Where to keep the .plist file in the iphone app

I am developing an iPhone app, in which i want use an .plist file to save some config variables. in my xcode where to create that .plist file and how to access it??? thank you,You would put in the resources folder. Then use something like this to loa

Android - where to keep the global data?

I have several 2D and 3D arrays that I'd like to access from multiple places within my app, which will be loaded from SharedPreferences as strings when my app starts and saved back to SharedPreferences whenever onPause() is called on any activity. It

How to highlight a ListView item using OnLongClickListener from the custom adapter class in Android

Here's what I want to do: In my main Activity I have a ListView with a custom Adapter because my ListView item should contain a TextView AND a CheckBox. When I do a long press on an item, I wanna use a contextual action mode in the ActionBar and HIGH

How to keep the WakeLock as long as an application is open / running?

I need to keep a SCREEN_DIM_WAKE_LOCK for as long as my application is running. Before somebody lectures me on good or bad practice and how this messes with the device's own power management, this will be on a dedicated device and are the client's ex

Call the Worklight Adapter from an external application

I have deployed the adapter on Worklight server and there is some requirement where I am calling worklight adapter from outside as a rest serverice , it is working fine and returning data as required but instead of giving json output it is giving HTM

How to convert a bitmap view and keep the same item size in Android?

I'm trying to convert a view which contains another inflated view to a bitmap but when execute the code and the see the results it's not the same image that I want,it is wrapping up the elements together .How can i do to keep the view as it is in the

How can I keep the size of a small Delphi application when it has a lot of TImage components?

I want to make an application using Delphi. The problem is I am going to have a lot of TImage components in it - which will make the exe size extremely large. So far my exe is 20MB large and I have only completed the home page, by my calculations the

How to use the OSM card in an Android application? Is there a tutorial to learn how to use OSM in Android?

Hi guys from past one week i'm searching for a tutorial/manual or steps to include Open street map into my android application. All i found is either a big project with lot more functionality on it, otherwise so many questions ended without proper co

How do I ask the user to install another Android application (including my app), during my application installation?

In desktop applications, for example, many applications ask us to install .Net framework during their installation. So my question is that during the installation of my Android application on a user's device, how can I notify the user that this appli

How to see all the threads generated by an Android application

I have an android application where I am performing some operations in background threads. For some reason my app becomes extremely slow and unresponsive after being used for few minutes. I am suspecting that it is because of some background thread,

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK