is a view's “tag” restored when the activity whose layout contains the view is recreated?

依然范特西╮ 提交于 2019-12-21 08:17:08

问题


The docs concerning Activity recreation state:

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.

The docs for View.setTag(Object) state:

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.

My question is: 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?


回答1:


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?

No, based on my reading of the source code.

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

That is not always possible, as the saved instance state Bundle needs to be transportable across process boundaries.



来源:https://stackoverflow.com/questions/16172637/is-a-views-tag-restored-when-the-activity-whose-layout-contains-the-view-is-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!