Where to keep Retrofit Adapter in Android App?

后端 未结 2 524
迷失自我
迷失自我 2021-01-16 04:42

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 inte

2条回答
  •  花落未央
    2021-01-16 05:09

    Retrofit 1.7 doesn't allow one to perform request-specific operations, specifically the RequestInterceptor. Because of this I'm using a map of Singletons where each API gets its own RestAdapter. This way I can control Headers and such that are specific to an API.

    I also give consumers of my library the ability to create a local API+RestAdapter combo for one-off scenarios if the need arises.

提交回复
热议问题