Last active
April 17, 2018 08:12
-
-
Save PierceZ/07c734ad458462355d848c3e9ab93ec7 to your computer and use it in GitHub Desktop.
An example of how to use the LiveDataBus class.
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
//Example Activity | |
public class MyActivity extends BaseActivity { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.myactivity); | |
// with lambda | |
LiveDataBus.subscribe(LiveDataBus.SUBJECT_DATA_LOADED, this, (data) -> { | |
Log.d("Testing my data", (String)data); | |
}); | |
//without lambda | |
LiveDataBus.subscribe(LiveDataBus.SUBJECT_DATA_LOADED, this, new Observer<Object>() { | |
@Override | |
public void onChanged(@Nullable Object data) { | |
Log.d("Testing my data", (String)data); | |
} | |
}); | |
} | |
} | |
//Example data published (this could be anywhere in your app) | |
LiveDataBus.publish(LiveDataBus.SUBJECT_DATA_LOADED, "Hello world"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment