jojoBelt
jojoBelt

Reputation: 1

Kotlin LiveData in object class

I have defined singleton in Kotlin as object class where I have connection to Room database and most logic is written in this class. I have defined LiveData, but its value is null, since there must be observer to work.

How can I implement observer in object class? Is this possible since function observe() takes Lifecycle as paramer?

Upvotes: 0

Views: 691

Answers (1)

Demigod
Demigod

Reputation: 5635

Use

MutableLiveData<String>().observeForever {  }

method, which doesn't care about the lifecycle. Please post some code or better explain what you want to more relevant answer.

Upvotes: 1

Related Questions