Android中使用Notification
来源:互联网 发布:360杀毒软件for mac 编辑:程序博客网 时间:2024/05/22 06:50
大家都知道在iOS中Controller之间传递数据最常用的就是delegate和通知了,特别是通知,可以很方便在任何对象直接传递数据,而且是很好的解耦设计. 在Android之中 传递数据一般用Intent的data功能, 但是如果数据传递比较复杂,这就比较麻烦. 在Android中有广播组建,但是一般用于应用之间,效率比较低.而且做界面更新的时候也比较困难. 今天我要给大家介绍的是一个Android版本的Notification,使用的api和iOS的 Notification几乎一样.
1.注册通知
//向通知中心注册通知 NotificationCenter.getInstance().addObserver(this,this.getClass().getMethod("onNotification",Notification.class),"NotificationName",null);//当监听到通知public void onNotification(Notification notification){ System.out.println("接收到通知"+notification); //TODO 界面更新和其他处理 } //当Activity销毁时从通知中心取消注册@Overrideprotected void onDestroy() {super.onDestroy(); NotificationCenter.getInstance().removeObserver(this); }
2.发送通知
//发布通知Map<String,Object> userInfo = new HashMap<>();userInfo.put("key","value");NotificationCenter.getInstance().postNotification(this,"NotificationName",userInfo);
- github 下载地址
1 0
- Android中使用Notification
- 在Android中使用Notification
- Android中Notification的使用
- Android中Notification的使用
- Android中使用通知Notification
- Android中Notification的使用
- Android中使用Notification并通过点击Notification重新启动Activity
- Android中使用Notification并通过点击Notification重新启动Activity
- 在Android中使用Notification进行提示
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- 在Android中使用Notification进行提示
- 在Android中使用Notification进行提示
- Android中通知的使用-----Notification详解
- Android中Notification的使用以及自定义
- Android中通知的使用-----Notification详解
- android中通知栏notification的使用
- Android开发中Notification的使用
- Nginx + Tomcat 实现动静分离
- RMI在外网不能通信的解决
- 【源码分享】-wpf界面源代码分享
- unity5之monodeveloper新发现
- 关于swift,OC,C++混合编程(一)
- Android中使用Notification
- 关于swift,OC,C++混合编程(二)
- 【源码分享】-c++界面源代码分享
- android unknown offline
- 【源码分享】-c#界面源代码分享
- js----Number对象
- Nginx源码main函数解读
- NetBeans8.0启动tomcat8.1.15失败--'127.0.0.1' 不是内部或外部命令
- lua 中pairs 和 ipairs区别