// 订阅全局粘性 observeEvent<GlobalEvent>(isSticky = true) { } // 订阅全局非粘性 observeEvent<GlobalEvent> { } // 订阅activity粘性 observeEvent<ActivityEvent>(owner = activity as ComponentActivity, isSticky = true) { } // 订阅activity非粘性 observeEvent<ActivityEvent>(owner = activity as ComponentActivity) { } // 订阅fragment粘性 observeEvent<FragmentEvent>(owner = this@EventFragment, isSticky = true) { } // 订阅fragment非粘性 observeEvent<FragmentEvent>(owner = this@EventFragment) { } // 范围: 全局 postEvent(GlobalEvent("全局")) // 范围: activity postEvent(activity, ActivityEvent("activity")) // 范围: fragment postEvent(this@EventFragment, FragmentEvent("fragment"))在项目的 build.gradle 文件中配置仓库地址。
allprojects { repositories { ... maven { url 'https://jitpack.io' } } } 在需要添加依赖的 Module 下添加以下信息,使用方式和普通的远程仓库一样。
implementation 'com.github.yangsanning:EventBus-ktx:1.0.0'