Android EventBus 传递消息
来源:互联网 发布:丝路传说 依人网络 编辑:程序博客网 时间:2024/05/23 11:35
挺好用的 试了一下在 Activity 和 Service 里面传递消息
public class MyService extends Service { @Override public IBinder onBind(Intent intent) { throw new UnsupportedOperationException("Not yet implemented"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { //三个参数分别是,消息订阅者(接收者),接收方法名,事件类 EventBus.getDefault().register(this, "test", TestEvent.class); return super.onStartCommand(intent, flags, startId); } public void test(TestEvent event) { Log.e("e", "e"); }}
startService(new Intent(MainActivity.this, MyService.class)); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EventBus.getDefault().post(new TestEvent()); } });
register之后就可以post了
0 0
- Android EventBus 传递消息
- Android EventBus 传递消息
- Android消息传递利器EventBus
- 消息传递之:IOS NSNotificationCenter,Android EventBus;
- Android中通过EventBus传递消息数据
- 【android】消息传递利器EventBus的使用
- Android之利用EventBus进行消息传递
- Android消息传递之EventBus 3.0使用
- Android:EventBus的使用 从此消息传递变得简单
- Android消息传递之EventBus 3.0使用详解
- Android消息传递之EventBus 3.0使用详解
- Android消息传递之EventBus 3.0使用与案例
- (转)Android消息传递之EventBus 3.0使用详解
- Android消息传递之EventBus 3.0使用详解
- android 消息传递机制EventBus的深入探究
- Android消息传递之EventBus 3.0使用详解(转载)
- Android消息传递之EventBus 3.0使用详解
- Android消息传递之EventBus 3.0使用详解
- iOS边城之事件(Events)
- Android Activity之间跳转出现短暂黑屏的处理方法
- ThinkPHP的增删改查
- http协议请求和相应
- STL源码剖析---红黑树原理详解下
- Android EventBus 传递消息
- 关于用addr2line解析函数地址的一个小探索
- Android AsyncTask介绍
- Android 中Animations的使用 xml篇
- MULE ESB 配置(三)
- Python中的函数定义及参数
- springMVC的中文乱码问题
- Spring基于 Annotation 的简单介绍
- Android NDK和OpenCV整合开发 (1) 环境搭建