简体   繁体   中英

Multiple LiveData observer call sequence

Let's say I have one LiveData l and multiple Observers o1, o2, o3 observing on l . When value of l changes, what sequence does the observers get called? Is it the sequence that the observers are attached to l ? Or is it non deterministic?

I'd expect the former.

LiveData uses SafeIterableMap.iteratorWithAdditions() to iterate over its observers and notify them. The documentation described SafeIterableMap as a "LinkedList, which pretends to be a map".

from source code it looks like it iterates all the observers and notify them about change with data.

for (Iterator<Map.Entry<Observer<? super T>, ObserverWrapper>> iterator =
                        mObservers.iteratorWithAdditions(); iterator.hasNext(); ) {
                    considerNotify(iterator.next().getValue());
                    if (mDispatchInvalidated) {
                        break;
                    }
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM