在应用程序中保留实际数据的最佳方法 [英] Best way to keep actual data in application

查看:50
本文介绍了在应用程序中保留实际数据的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中的数据相关性方面遇到了一些问题.

I Faced some problem with the relevance of the data in application.

在我们的应用中,我们有1个活动和许多片段.

In our app we have 1 activity and many fragments.

例如,我们有1个Fragment,其中包含User(用户)列表,并且有like(关于3个状态的按钮):none/like/favorite(无/喜欢/喜欢).在下一页中,我们也有对User和点赞按钮的完整描述.如果我们在userList中按下赞"按钮,将没有问题,并且在详细信息屏幕中,我们看到了正确的赞"状态.但是,如果我们在用户详细信息"中单击喜欢"按钮,然后返回列表,则此处仍然有过去的数据.

For example, we have 1 Fragment with list of User and there button for like(with 3 states: none/like/favorite). In next page we have full description of User and like button too. If we press like button in userList, there will be no problem and in details screen we see correct like state. But if we click like button in User details and go back to list, there still past data here.

由于片段,我们不能使用activityForResult.

We can't use activityForResult because fragment.

我们使用rx,也许有某种方法可以轻松解决此问题?

We using rx, maybe there some way to easy resolve this problem?

推荐答案

为了重用 Fragment UI组件,您应该将每个组件构建为一个完全自包含的模块化组件,该组件定义自己的组件布局和行为.然后,每个 Fragment 都可以将数据传递到 Activity ,并且 Activity 也可以将数据发送到 Fragment s.

In order to reuse the Fragment UI components, you should build each as a completely self-contained, modular component that defines its own layout and behavior. Each Fragment then can communicate data to the Activity, and the Activity can also send data to Fragments.

在您的情况下,活动可以保存实际数据.当用户修改详细信息 Fragment 中的某些内容时, Fragment 应该将其与 Activity 紧密相关. Activity ,然后应依次通知列表 Fragment .

In your case, the Activity can hold the actual data. When user modifies something in the details Fragment, the Fragment should intimate that to the Activity. The Activity, then in turn should inform the list Fragment.

这篇关于在应用程序中保留实际数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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