简体   繁体   English

在片段生命周期中调用REST服务的正确位置

[英]Right place to call REST service in fragment lifecycle

What is the best place in fragment lifecycle to call REST service for example to fill ListView with received data ? 在片段生命周期中调用REST服务(例如用接收到的数据填充ListView )的最佳位置是什么? There are onCreateView , onActivityCreated and onResume . onCreateViewonActivityCreatedonResume My first thought was to call network service as soon as possible, so on the end onCreateView , but i'm confused about this. 我的第一个想法是尽快调用网络服务,所以最后是onCreateView ,但对此我感到困惑。

Just don't bind REST calls to your UI. 只是不要将REST调用绑定到您的UI。 You should split up UI and business logic responsible for getting and updating data. 您应该拆分负责获取和更新数据的UI和业务逻辑。 UI is just a facade so you shouldn't try to call any network services from UI. UI只是一个外观,因此您不应尝试从UI调用任何网络服务。 You can implement any of the patterns described by Virgil Dobjanshi in IO Talk 您可以实现IO Talk中 Virgil Dobjanshi描述的任何模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM