gpt4 book ai didi

android - 当重新创建其布局包含 View 的 Activity 时,是否恢复了 View 的 "tag"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:09:13 26 4
gpt4 key购买 nike

docs关于 Activity 娱乐状态:

By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you.

docs对于 View.setTag(Object) 状态:

Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.

我的问题是:如果我在 Activity 布局中的 View (具有唯一 ID)上设置标签,然后该 Activity 被系统销毁并随后重新创建,那么该 View 在重新创建时是否会自动用我最初设置的对象标记?

最佳答案

if I set a tag on a View (that has a unique id) in my activity's layout and then the activity is destroyed by the system and subsequently re-created, will that view, when recreated, automatically be tagged with the Object I originally set?

不,基于我对源代码的阅读。

The system expects to recreate the activity at some later date, so I could see it keeping around a reference to the original tag.

这并不总是可能的,因为保存的实例状态 Bundle 需要跨进程边界传输。

关于android - 当重新创建其布局包含 View 的 Activity 时,是否恢复了 View 的 "tag"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16172637/

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