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使用详解
- HDU 2647 Reward
- ADB server didn't ACK * failed to start daemon *
- 2014-8-31 怎么样静心编程
- 2014RubyConf China 圆满落幕,GitCafe 带您一起回顾!
- 2014年8月迟到总结
- Android EventBus 传递消息
- Android UI Fundamentals Develop and DesIgn笔记
- Swift dispatch_after替代ios performSelector
- Android检测当前屏幕的方向
- bootstrap学习笔记(一)如何在网页中使用bootstrap
- playframework 一步一步来 之 日志(一)
- CGContext Transform
- Cocos2d-x Lua实现从Android回调到Lua的方法
- cocos2d-x V3.x内存管理分析