gpt4 book ai didi

android - 没有 View ID 时的 onSaveInstanceState Activity

转载 作者:行者123 更新时间:2023-11-30 01:51:29 24 4
gpt4 key购买 nike

Activity#onSaveInstanceState 的默认实现说:

The default implementation takes care of most of the UI per-instance state for you by calling onSaveInstanceState() on each view in the hierarchy that has an id

Android 数据绑定(bind)指南,以及 this video - 幻灯片 9 建议我们在使用数据绑定(bind)时不再需要 View ID。我的问题是:缺少 View ID 对状态保存/恢复有何影响?

可以说,当使用数据绑定(bind)时,不应该依赖于默认机制来保存/恢复状态,而是依赖于绑定(bind)到布局的 ViewModel 以获得最新状态,但我仍然很想知道其中的含义。

最佳答案

您不需要 ID 并不意味着您不应该使用 ID。那是为了更新您的观点。在许多其他情况下,id 就像 RelativeLayout 中的规则一样有用。

因此,如果状态恢复对您的用例很重要(例如,您的模型需要一段时间才能恢复),请务必放置 ID 并禁用绑定(bind),直到您的数据准备就绪。

关于android - 没有 View ID 时的 onSaveInstanceState Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32964972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com