0

I have a domain object, let's say User:

class User(var id: String, var name: String) {

   init {
       EventBus.getDefault().register(this)
   }

   @Subscribe(threadMode = ThreadMode.MAIN)
    fun onNewName(event: NewNameEvent) {
        this.name = event.newName
    }
}

This class is notified by global EventBus. From the other side, there is a ViewModel (of activity) which has:

val user = MutableLiveData<User>(Application.my.user)

Issue is that viewModel's user doesn't react on any changed made by event bus in Application.my.user. What do I miss?

nKognito
  • 6,297
  • 17
  • 77
  • 138

1 Answers1

0

The problem is that LiveData is listening for changes of the User object and not its fields. This is a solution to a problem similar to yours.

Stoyan Milev
  • 725
  • 4
  • 17