Where to keep Retrofit Adapter in Android App?

后端 未结 2 523
迷失自我
迷失自我 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条回答
  •  梦毁少年i
    2021-01-16 05:11

    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).

提交回复
热议问题