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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With