I am looking for a practical example for both the cases that what to use when? I have seen similar threads but they only tell this "when binding must be executed immediately" but there is no real time example for any case where you have to force the binding to be executed. So please if anyone can explain with any example that when to use it and when its not that required!
The case when you should use executePendingBindings()
is (but there could be more):
Every time the binding update could cause a View to change its size and postponing the calculation in the next frame could cause the measurement to read wrong values.
In case of a RecyclerView
, this happens if:
viewType
s with different sizes (different XML)RecyclerView
will measure the row size after the onBindViewHolder
has completed. If based on the data you set in this method the height of the row changes, the measurement could not take into account the extra or reduced space occupied by your new content if you do not call executePendingBindings()
.
Forcing the binding to update data synchronously and not in the next frame keeps you safe from wrong row size measurement (and potentially missing content)