Last active
April 17, 2018 08:12
-
-
Save PierceZ/c1acdb22cc2f98ba586a6b45e2c978ba to your computer and use it in GitHub Desktop.
A LiveData implementation for my event bus to send Objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventLiveData extends LiveData<Object> { | |
private final int mSubject; | |
public EventLiveData(@LiveDataBus.Subject int subject) { | |
mSubject = subject; | |
} | |
public void update(Object object) { | |
postValue(object); | |
} | |
@Override | |
public void removeObserver(Observer<Object> observer) { | |
super.removeObserver(observer); | |
if (!hasObservers()) { | |
LiveDataBus.unregister(mSubject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment