EventBus配置、粘性事件、优先级和取消事件分发
EventBus配置
EventBus eventBus = EventBus.builder()
.logNoSubscriberMessages(false)
.sendNoSubscriberEvent(false)
.build();粘性事件
public void downloadPage(View view) {
EventBus.getDefault().postSticky(new DownloadEvent());
startActivity(new Intent(this,SecondActivity.class));
}@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
EventBus.getDefault().register(this);
}
@Subscribe(sticky = true)
public void download(DownloadEvent downloadEvent) {
Toast.makeText(this,"Receive Sticik Event",Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}手动获取和取消粘性事件
优先级
取消事件分发
Last updated