Android Internet Check Layer

寵の児 提交于 2019-12-10 22:33:43

问题


I am creating an Android application which basically calls an web service and shows back the response; and I am following the MVP pattern to accomplish it. So the biggest & basic challenge is to check the internet status before every call. I was thinking to create an Abstract layer between the Presenter & the API. So the API request will pass first from the Abstract Internet Layer and if it passes successfully then only the API will get called.
Creating a separate layer looks a better solution in my opinion rather than calling the Internet check logic from Presenter, every time. Please help me with the design if you've any better idea. Thanks


回答1:


You can create a BasePresenter, that presenter will be a super class of all your presenters. Now in BasePresenter you can write your common APIs (protected/public) stuff like making http request, showing loader, check for internet connectivity etc.

Each time when you make http call via BasePresenter, your BasePresenter will first check for the requirements and then makes an http call to the server. This is because of, it will be always easy to change anything related to http logic or internet check logic or anything. Because everything will be at one place only (BasePresenter) and easily accessible to the sub presenters.

So, by this way you can achieve the feature implementation.



来源:https://stackoverflow.com/questions/37589008/android-internet-check-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!