《第一行代码》中失效内容的替换
来源:互联网 发布:免费发光字制作软件 编辑:程序博客网 时间:2024/05/21 19:35
学习《第一行代码》一段时间了,发现书中提到的一部分的方法已经失效了,如书中所用的Notification构造函数以及用Notification.Builder替代了。这里我就写写个人发现的失效的部分已经新的方法,希望能帮助到跟我一样的新手,新手找这些资料还是挺花时间的(特别是像我这样的小白)。
第一次写blog,有错误的地方希望指出。如果还有发现持续更新。。。
第8章.第300页
失效的内容:Notification构造函数(3参数的)
setLatestEventInfo方法
新的代码:
<span style="font-size:14px;">@Overridepublic void onClick(View v) { switch (v.getId()){ case R.id.send_notice: NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); <span style="white-space:pre"></span> Notification.Builder builder = new Notification.Builder(this);//创建Notification.Builder对象 builder.setContentTitle("This is content title");//设置通知标题 builder.setContentText("This is content text");//设置通知内容 builder.setSmallIcon(R.drawable.ic);//设置通知图标 Notification notification = builder.build();//用build方法生成Notification对象 manager.notify(1,notification); break; default: break; }}</span>
第8章.第304页
失效的内容:setLatestEventInfo方法
新的代码:
<span style="font-size:14px;"> @Override public void onClick(View v) { switch (v.getId()){ case R.id.send_notice: Intent intent = new Intent(this,NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("This is content title"); builder.setContentText("This is content text"); builder.setSmallIcon(R.drawable.ic); builder.setContentIntent(pi);//用setContentIntent方法替代,传入PendingIntent对象 Notification notification = builder.build(); manager.notify(1,notification); break; default: break; } }}</span>
0 0
- 《第一行代码》中失效内容的替换
- 第一行代码-7.3 创建自己的内容提供器
- vim 替换一行内容
- 自动替换页面失效图片的代码
- Hadoop的第一行代码
- Kotlin的第一行代码
- 第一行代码中遇到的小问题
- 【android】第一行代码CoolWeather中遇到的问题
- 第一行代码中过时的通知写法更正;
- 第一行代码-第7章 内容提供器
- [Android][第一行代码][第 7 章 内容提供器]
- eclipse中将代码中某个相同的内容全部替换
- 【第一行代码】Android中UI总结
- 第一行代码中相机问题
- 第一行代码学习笔记,第七章 内容提供者
- 《第一行代码》读书笔记(十一)----内容提供器
- 《第一行代码--Android》读书笔记之内容提供器
- 第一行代码-7.1 内容提供器简介
- 18--26 面向对象程序设计24(深入解析原型继承的概念)
- SDOI知识点大复习
- c++实现快排。。下午补充
- MFC Edit控件之enter回车捕捉
- EditText的光标在中间的问题
- 《第一行代码》中失效内容的替换
- Java中的static关键字解析
- android仿qq实现自定义拍照界面CameraView
- js note
- 虚拟机virtualBox 搭建 Keepalived+lvs dr+httpd 负载均衡
- 排序七部曲之(四)快速排序
- ORA-00907: 缺失右括号
- 硬件研发工程师任职要求
- HDU 2391 Filthy Rich (滚动dp)