EventBus Otto and third-party framework

Code

Add Dependency:
Implementation 'org.greenrobot: EventBus: 3.0.0'
1
registration statement and subscribers, and then publish the final event deregistration
@Override
protected void the onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout .activity_main);

button = findViewById(R.id.bt);

button.setOnClickListener (new new View.OnClickListener () {
@Override
public void the onClick (View V) {
// send information
EventBus.getDefault () postSticky (new MessageEvent ( " pit occupation",. 17, to true));.
}
} );
EventBus.getDefault () Register (the this);.
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void show(MessageEvent event){
Toast.makeText(this, ""+event.getName()+":"+event.getAge()+":"+event.isSex(), Toast.LENGTH_SHORT).show();
}

@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/11329167.html
Recommended