1.要使用EventBus,需要去Maven官网找到依赖
点击project视图–app文件夹–build.gradle文件
添加依赖,关键词:implementation,注意格式
2.准备布局文件
(1)MainActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"/>
<Button
android:id="@+id/btn_give_up_reg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="取消注册"/>
<Button
android:id="@+id/btn_post"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发布普通事件"/>
<Button
android:id="@+id/btn_post_sticky"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发布粘性事件"/>
<TextView
android:id="@+id/tv_show_msg"