Event 2.4 跳转接收消息
来源:互联网 发布:树型网络拓扑结构 编辑:程序博客网 时间:2024/06/03 05:37
依赖: (导Event 的 jar包)
compile files('libs/EventBus2.4.jar')
无网络请求
MessageEvent
public class MessageEvent {//类的用途 事件类 用于封装消息 private String msg; public MessageEvent(String msg) { this.msg = msg; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; }}MainActivity/** * 订阅消息的页面 */public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //注册EventBus 单例设计模式 EventBus.getDefault().register(this); findViewById(R.id.bt_jump).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(MainActivity.this,Main2Activity.class)); } }); } /* public void onEvent(MessageEvent event){ Toast.makeText(this, "我接收到了EventBus发送过来的消息", Toast.LENGTH_SHORT).show(); }*/ public void onEventMainThread(MessageEvent event){ Toast.makeText(this, "我接收到了EventBus发送过来的消息", Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); //页面销毁的地方注销掉EventBus EventBus.getDefault().unregister(this); }}
xml:<Button android:id="@+id/bt_jump" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/>
Main2Activity:<Button android:id="@+id/bt_jump" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/>
xml2:<Button android:id="@+id/bt_send" android:text="发送消息" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
阅读全文
0 0
- Event 2.4 跳转接收消息
- iOS接收推送消息跳转相应的页面问题
- 消息接收
- 接收消息
- 接收消息
- 页面跳转参数接收
- /*接收消息--单项的接收消息*/
- gloox接收消息
- gloox接收消息
- gloox 接收消息
- gloox接收消息
- windows接收登陆消息
- 消息队列的接收
- gloox接收消息
- NUGI poplist接收消息
- 消息接收线程
- asmack消息接收
- 微信接收消息
- Struts2 拦截器(一)
- Linux命令(3)-grep文本搜索
- EventBus2.4
- linux学习
- 软考之旅
- Event 2.4 跳转接收消息
- javascript中用=给数组赋值
- 【二分图多重匹配 && Dinic】POJ
- 设计模式—观察者模式
- 多线程的问题:如何保证界面的分页参数安全的传递到dao层?
- ActiveMQ(3)-ActiveMQ+MySQL持久化
- C和指针之二维字符串数组用指针数组、数组指针、二级指针打印
- linux遇到的问题
- 计算并输出两个整数的最大值