How to use the event Bus in Android Studio.
Create the Event bus class.
public class MessageValueBus {
    public String value;
    public String checkValue;
    public MessageValueBus(String value,String checkValue) {
        this.value = value;
        this.checkValue = checkValue;
    }
    public String getValue() {
        return value;
    }
    public String getCheckValue() {
        return checkValue;
    }
}
 
//Pass the value in event Bus
EventBus.getDefault().postSticky(new MessageValueBus("your pass value","your pass value"));
//Call the event bus value 
@Overridepublic void onStop() {
    super.onStop();
    EventBus.getDefault().unregister(this);
}
@Overridepublic void onStart() {
    super.onStart();
    EventBus.getDefault().register(this);
}
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(MessageValueBus eventBus) {
    if (eventBus.getValue().equals("")) {
    } else {
 
      String mCheckValue = eventBus.getCheckValue();
       
    }
}
 
 
 
No comments:
Post a Comment