Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 680
jph Avatar asked Apr 23 '13 14:04

jph


1 Answers

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.

like image 109
CommonsWare Avatar answered Nov 11 '22 09:11

CommonsWare