Lore
Lore

Reputation: 1968

How to find where a LiveData is observed

I am studying a project with LiveDatas on Android Studio (Java). I would like to know if it exists an Android Studio option to see where a particular LiveData is observed in the project, to see all the objects that are been notified and in which method.

Upvotes: 0

Views: 1766

Answers (3)

Lore
Lore

Reputation: 1968

It seems that the best solution, to me, is to find usages of the particular LiveData's getter method of viewModel, then see when the LiveData is observed after get.

Upvotes: 0

Thalis Vilela
Thalis Vilela

Reputation: 345

You can't do that. Android studio can't give you such "runtime" information. The best you can do, is to call LiveData's hasActiveObservers() returns true if there are active observers, or hasObservers() returns true if there are any observer.

Upvotes: 0

Zafer Celaloglu
Zafer Celaloglu

Reputation: 1418

you can access by typing .observe into Find in Path(cmd + shift + f in Mac):

sample live data observing:

viewModel.liveData.observe(this, Observer {})

Upvotes: 3

Related Questions