Android 系统相关
源码
不同的版本的源码可能同一个方法的内部实现完全不用,抛弃源码版本谈论具体的实现没什么意义。
StartActivity
- 启动 Activity 到 AMS
- AMS 到 ApplicationThread
- ApplicationThread 到目标 Activity
旁系知识
App 最少有几个线程
- Main
- Binder 收
- Binder 发
- RenderThread「5.0 之后新加的渲染线程,Main 在 drawCall 之后调用 sync 方法给 RenderThread,交由 GPU 进行绘制。具体参见:Android Systrace 基础知识 - MainThread 和 RenderThread」
适配
Android 11 适配
Android 11 适配麦克风及摄像头权限为单次授权引起系统主动回收。
解决方案:
启动一个前台 Service,参考 KeepLiveAliveService
可以将 targetSdkVersion 改为 30
启动一个前台 Service,在 Manifest 中声明 Service 时,加入 android:foregroundServiceType="camera|microphone"
属性。
不方便将 targetSdkVersion 改为 30
可省略 android:foregroundServiceType="camera|microphone"
属性,可用。