Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of View.hasTransientState()

Tags:

android

Specifically setHasTransientState(boolean). How and why would one use it? I'm looking for a "real life" scenario.

The docs definition:

Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible. This flag is reference counted, so every call to setHasTransientState(true) should be paired with a later call to setHasTransientState(false).
A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.

like image 402
Alex.F Avatar asked Nov 21 '22 02:11

Alex.F


1 Answers

If the view is listview item, setHasTransientState can prevent it from recycling.If it is in animation, it is userful. Transient is just a special state of view, I think it means dont touch me(as recycle),and I will become not transient soon.

like image 200
chefish Avatar answered Jun 20 '23 03:06

chefish