Currently my project used EventBus to post event and I am trying to replace LiveData with EventBus. In theory, they work similarly. I migrated without no pain in the beginning. But it comes up a scenario I have no idea how to deal with it.
And here's is the scenario.
LaunchActivity -> PersonInfoActivity -> UpdateInfoActivity
Currently We use EventBus to subscribe UserInfoEvent in LaunchActivity and PersonInfoActivity
LaunchActivity.java
public class LaunchActivity{
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(UserInfoEvent event){
}
}
PersonInfoActivity.java
public class PersonInfoActivity{
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(UserInfoEvent event){
}
}
UpdateInfoActivity.java
public class UpdateInfoActivity{
public void onSubmit(){
EventBus.getDefault().post(new UserInfoEvent());
}
}
And the question is , I want to use LiveData to replace this scenario
What I have done?
I have read about the question about singleton usage with livedata Room - LiveData observer does not trigger when database is updated, I want to try to use the same way but no luck. The Event is fire everytime in onChanged()
when I started the Activity