QED
QED

Reputation: 9923

Android LiveData order of observation

I have a LiveData and, say, n Observers of it. One of the Observers, call it o, updates global state, upon which the other n-1 Observers depend.

Is there any way to guarantee that o is executed first? Is it merely that o be added first?

I've looked through the relevant docs and see nothing mentioned explicitly.

Upvotes: 1

Views: 700

Answers (1)

Pawel
Pawel

Reputation: 17258

Theoretically there's no specific guarantee declared that I'm aware of.

Practically as long as all of your observers are added using the same lifecycleOwner they should be invoked in registration order as LiveData internally uses forward iteration (source code) to update them.

Upvotes: 2

Related Questions