Andrews components
The components in the Android 1
- Two kinds of Hello World
Inheritance Activity, achieve OnCreate ()
Four major components:
- Activity content display, interaction with users
- Service long-running background
- BroadcastReceiver receive information, take the initiative to make a deal
- Management and sharing application data Content Provider
2 intent type:
Two kinds
Explicit Intent: know the name of components, only one component can handle
Implicit Intent: General statement operation performed in response to a plurality of applications running;
ps: Start Service, an explicit Intent
3 intent matching rules
Implicit Intent matching rules in three dimensions
- action matching rules:
- Category matching rules
- data matching rules
Debugging intent tips: am Send intent commands to start the activity
语法:adb shell am start a、t、d、e、n
4 intent information transfer
Basic types:
Eight basic types of java + String reference type + CharSequence
Complex object in two ways:
- Serializable: serialize object into storable, only implements Serializable
- Parcelabe: between different components, better performance, inter-memory data transfer, need to customize packing and unpacking, preferred
5 Activity Lifecycle Management
Press the return key:
- Start the application onCreate-onStart-onResume
- Press return onPuse- Onstope- onDestrov
- Restart start onCreate-onStart-onResume
Press the Home key, Configuration change (screen rotation, change the font size, change the language, keyboard display hidden switch fonts, themes)
There will be restarted onDestroy, onCreat
6 ascend into the interface speed
Time Test Method: adb shell am start -W [packageName] / [PackageName.MainActivity]
Application launch key processes:
开始, Zygote创建进程--创建初始类Applicat--创建Acitivity--onCreate--配置主题信息--onStart--onResume--Measure/layout--显式
优化的策略
- 耗时任务异步处理(onCreate(),onResume())
- 布局优化
- 减少布局层次去除冗余
- merge标签
- 自定义组件
- Viewstub
- 不可视图延迟加载
- 资源分开初始化
- addView
- 页面分开加载
7 service生命周期管理
后台长时间执行运行操作,不需要提供界面
启动方式
- bindService (组件与服务进行交互,发送请求)
- startService
- 服务启动后可以无限期运行
- 启动服务的组件已经被销毁了也不受影响
8 绑定Service
三种方式参考点
扩展Binder类(用用程序私有,客户端运行一个进程
服务端提供客户端可调用
扩展返回服务实例
Messenger(不同进程间的通信,每次处理一个请求
- 客户端使用ibinder将message实例化,
- message对象向服务发命令
AIDL文件(不同进程间, 服务每次处理多个请求
- Android接口定义语言
- 将对象解析为可识别的方式
9 接收器的注册
BroadcastReceiver用来响应系统范围内的广播事件的组件
事件----》AMS发送广播-----》APP(BroadcastReceiver)启动服务
两种注册方式:
- 静态注册 AndroidManifest.xml中声明
- Activity
- Service
- BroadcastReceiver
- ContentProvider
- 动态注册Context的子类中添加(BroadcastReceiver)
比较:静态注册常驻型,程序关闭亦可激活,动态注册非常驻,注册和注销需要成对出现。
10 广播的发送
无序广播:发送接受者内容相同,接受者不受到影响
有序广播:先到优先级高的接受者, 接受者可以停止广播,优先级可以获得经过处理的信息;
BroadcastReceiver 生命周期管理
从调用开始,到OnReceiver执行结束;
Android 教程
系统架构:
调试
通过单击工具栏上的按钮, Debug 'All Tests' 菜单命令,或者按 Shift+F9 快捷键,启动程序的调试模式
- 快捷键 F8 单步执行程序。
- 快捷键 F7 单步执行程序,遇到方法时进入。
- 快捷键 Alt+F9 运行到光标处。
Activity声明周期,运行机制
‘参考书籍:《第一行代码》《Android 群英传》
Android Studio应用开发实战详解