1. 声明
本文并非出于分享目的,而是笔者最近开始找工作和面试需要,整理的一份 Android 面试复习指南。内容包括:自己写的笔记、书籍摘抄、网友文章链接等等。
准备面试过程中越发觉得:需要整理出一份属于自己的 Android 知识体系笔记,作为自己的复习材料。会更自信。
2. 参考书籍
3. Activity 启动模式
4. 生命周期
Activity
This
onRestoreInstanceState()
method is called betweenonStart()
andonPostCreate(Bundle)
.
If
onSaveInstanceState()
called, this method will occur afteronStop()
for applications targeting platforms starting withBuild.VERSION_CODES.P
. For applications targeting earlier platform versions this method will occur beforeonStop()
and there are no guarantees about whether it will occur before or afteronPause()
.
Fragment
Activity 和 Fragment 结合
5. 事件分发机制
6. View 工作原理
7. Drawable 体系
8. 消息机制
9. VSYNC 机制
10. 性能优化
涉及:优化工具、App 启动速度、布局优化、ANR 优化、卡顿优化、内存优化、网络优化、电量优化等。
10.1 内存泄漏
10.2 布局优化
工具:Hierarchy Viewer,Android Lint,Layout Inspector。
思想:减少布局层级。
手段:
- 尽量不嵌套 RelativeLayout。
- 尽量不在嵌套的 LinearLayout 中都使用 layout_weight。
- 选择 ViewGroup 应以尽量减少 View 层级为主。
- 删除布局中无用的控件和层级。
- 使用 TextView 的 Drawable 减少层级。
- 有选择地使用简单高效的
ViewGroup
。 - 使用
<include>
重用布局。 - 使用
<merge>
减少布局的层级。 - 使用
ViewStub
实现按需加载,提高程序初始化效率。
网络文章:
10.3 内存优化
10.4 ANR优化
ANR 产生条件:
-
5s内没有响应用户输入事件
-
10s内广播接收器没有处理完毕
-
20s内服务没有处理完毕
11. 动画机制
12. OkHttp
13. 面试
Binder
四大组件工作原理
多线程
- Retrofit
- Glide
- EventBus
- LeakCanary
- RxJava
- androidx.lifecycle
- androidx.room
- androidx.paging
- androidx.work
- androidx.navigation
- Kotlin
- kotlinx.coroutines
- JNI