Where to save the adapter for re-equipment in the Android application?

I don’t understand where the Refrofit adapters and API classes in Android should be supported? Should I use the Application or Singleton class to support the adapter? What about API classes?

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

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

I have several different api, such as MyApi1, MyApi2, which are called inside fragments at different points in the application.

thank

+1
source share
2 answers

Both of them should be considered as single and created only once.

RestAdaptercontains the general executor of requests, the general configuration of the HTTP client, information about remote services, etc. They should be used for each API.

API . (, ).

+11

Retrofit 1.7 , , RequestInterceptor. - Singletons, API RestAdapter. , , API.

API + RestAdapter , .

0

All Articles