eventbus 简单使用步骤

来源:互联网 发布:mysql用uuid作为主键 编辑:程序博客网 时间:2024/05/30 04:30

1. 注册

新建MyApplication extends Application,在onCreate()里写 EventBusBuilder builder = EventBus.builder();

builder.installDefaultEventBus();


2. 接收方在onCreate() 里写:

Eventbus.getDefault.register(this);

onDestroy()里写:

Eventbus.getDefault.unregister(this);


@Subscribe(threadMode = ThreadMode.MAIN) // 对UI进行更改,所以写在主线程中

public void xxx (我们定义的类){

实现

}


3. 发送方

Eventbus.getDefault.post(自己定义的类);

0 0