Skip to content

Instantly share code, notes, and snippets.

@PierceZ
Last active April 17, 2018 08:12
Show Gist options
  • Save PierceZ/07c734ad458462355d848c3e9ab93ec7 to your computer and use it in GitHub Desktop.
Save PierceZ/07c734ad458462355d848c3e9ab93ec7 to your computer and use it in GitHub Desktop.
An example of how to use the LiveDataBus class.
//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