Android互联网检查层 [英] Android Internet Check Layer

查看:177
本文介绍了Android互联网检查层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Android应用程序,它基本上称之为Web服务并显示响应;我正在跟随MVP模式来完成它。所以最大&基本的挑战是在每次通话之前检查互联网状态。我正在考虑在 Presenter & API 。因此,API请求将首先从抽象Internet层传递,如果它成功传递,那么只有API将被调用。

创建一个单独的图层看起来更好的解决方案在我看来,而不是每次从Presenter调用互联网检查逻辑。如果您有任何更好的想法,请帮助我设计。
谢谢

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

推荐答案

您可以创建一个 BasePresenter 演讲者将是您所有演讲者的超级班。现在在 BasePresenter 中,您可以编写常见的API(受保护/公开)的东西,例如使 http 请求,显示加载器,检查用于互联网连接等。

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.

每次通过 BasePresenter http code>,您的 BasePresenter 将首先检查要求,然后对服务器进行http呼叫。这是因为,更改任何与http逻辑或互联网检查逻辑或任何东西相关的事情总是容易的。因为一切都只在一个地方( BasePresenter ),并且可以轻松访问子演示者。

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.

这篇关于Android互联网检查层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆