EventBus is really powerful

Android development component communication, eventbus preferred, simple and convenient

First reference
// component communication tool in the project of android studio
//http://jcenter.bintray.com/org/greenrobot/eventbus/
// https://github.com/greenrobot/EventBus
implementation 'org.greenrobot: eventbus: 3.2.0 '
is easier to use, first you need to register on which interface you want to update, register on which interface
@Override
public void onStart () {
super.onStart ();
EventBus.getDefault (). register (this );
}

@Override
public void onStop () {
super.onStop ();
EventBus.getDefault (). Unregister (this);
}
Then, register an updated method and parameters, the parameters can not be empty,

For example, there is such a demand, I have a interface Insert picture description here
which is a non-registered status, click into the login screen
Insert picture description here
This is a login screen, after a successful login here to refresh my interface, we can do it
in my inside interface Add to

@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}

@Override
public void onStop () {
super.onStop ();
EventBus.getDefault (). Unregister (this);
}
@Subscribe (threadMode = ThreadMode.MAIN)
public void loginseccuss (UserInfo info) {
// This place is to receive login The parameter value returned successfully, the method name can be random, and the parameter must be the same as that passed on the login interface
}

After the login interface, you can send a message notification
EventBus.getDefault (). Post (new UserInfo ()); This parameter is consistent with the received
is not very simple and very convenient. When there was not before, you can register to receive data by broadcasting, but this is very inconvenient. Did the students learn?

Published 3 original articles · Likes0 · Visits 140

Guess you like

Origin blog.csdn.net/small44444/article/details/104701006