【Android】2015.09.08 第一行代码 Day6 Count:8
来源:互联网 发布:网络喷子到底是哪些人 编辑:程序博客网 时间:2024/05/29 04:00
-----------------------------------------------
第一行代码
Day6
第五章
Broadcast
-----------------------------------------------
Questions:
1. intent立flag到底是干嘛,它的default值到底是什么?
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
删掉会报错:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
2. 不设置就是Null? 我能明白这玩意儿是设置窗口类型,但是它的默认值到底是什么?
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
删掉会报错:
java.lang.RuntimeException: Unable to start receiver com.smile.broadcastbestpractice.ForceOfflineReceiver: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Points:
1. Broadcast
把握好两个方面:
Send:
全局广播无序发: this.sendBroadcast(intent);
全局广播有序发(配合优先级): this.sendOrderedBroadcast(intent,null);
本地广播:localBroadcastManager.sendBroadcast(intent);
Receiver:
两个参数:过滤器 —> IntentFilter.addAction() && 接收器 —> BroadcastReceiver
全局广播静态接收:(这样即使程序没有启动起来也可以实现接受,做出动作)
<receiver android:name=".MyBroadcastReceiver">
<intent-filter android:priority="100">
<action android:name="com.smile.broadcasttest.CC_CALL"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="com.smile.broadcasttest.CC_CALL"/>
</intent-filter>
</receiver>
本地广播动态接收:(能本地发送,程序一定启动了)
LocalBroadcastRecevier localBroadcastRecevier = new LocalBroadcastRecevier();
IntentFileter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
localBroadcastManager.registerReceiver(localBroadcastRecevier,intentFilter);
2.静态方法里用的都是静态变量,所以静态变量请在定义时初始化,而不是在构造函数中初始化,因为使用静态方法时不会调用构造函数的哦。
0 0
- 【Android】2015.09.08 第一行代码 Day6 Count:8
- 【Android】2015.09.01 第一行代码 Day2 Count:4
- 【Android】2015.09.02 第一行代码 Day3 Count:5
- 【Android】2015.09.04 第一行代码 Day4 Count:6
- 【Android】2015.09.07 第一行代码 Day5 Count:7
- 【Android】2015.09.09 第一行代码 Day7 Count:9
- Android第一行代码
- 《第一行代码Android》学习日记8
- 【Android】2015.08.31 安卓官方文档: Day3 第一行代码 Day1 Count:3
- 《第一行代码Android》读书笔记
- 《第一行代码Android》摘要
- 第一行代码-----Android 第一章
- 第一行代码Android-------Activity
- 《Android第一行代码》笔记
- 《第一行代码Android》笔记
- Android第一行代码读书笔记
- Android第一行代码小结
- 《第一行代码--android》笔记
- Sbt仓库设置
- 一元线性回归(原理)
- ps笔记
- uva 11526 H(n)
- PE格式详细讲解10 – 基址重定位
- 【Android】2015.09.08 第一行代码 Day6 Count:8
- poj 2464(区间更新)
- zookeeper集群安装配置
- Ibatis和myIbatis 返回插入的主键ID
- windows下mysql5.1忘记root密码解决方法[win7]
- Unity中的网络编程
- 工作中感受到的消息中间件在分布式系统中的使用场景
- jQuery插件开发
- mysql函数之——控制流函数