Issue
let's assume we have two Activities(A and B), when navigate from A(that has live data or flow) -> B then navigate back from B -> A.
if we observe using live data : live data will not observe the data again.
if we use collecting flow using repeatOnLifeCycle Api or(flowWithLifecycle) : to achieve Live data scenario we use Lifecycle.State.STARTED, but that will be different from live data when we navigate from A -> B then navigate back from B -> A , the flow is re-collecting . if some one explain the state and how they differ ,i will be grateful
Solution
i find the solution :
LiveData uses versioning to keep track of which value has been dispatched to which observer. This allows to avoid dispatching the same value twice to the same observer when it moves back to the STARTED state. StateFlow has no versioning. Each time a coroutine collects a Flow, it is considered as a new observer and will always receive the latest value first. This can lead to performing duplicate work as we will see in the following case study.
Answered By - Mohmmaed-Amleh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.