ANR问题分析和解决

ANR类型

按键或触摸事件在特定时间内无响应

1
2
3
4
//ActivityTaskManagerService.java

// How long we wait until we timeout on key dispatching.
public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000;

BroadcastRecevier超时

1
2
3
4
5
//ActivityManagerService.java

// How long we allow a receiver to run before giving up on it.
static final int BROADCAST_FG_TIMEOUT = 10*1000;
static final int BROADCAST_BG_TIMEOUT = 60*1000;

前台广播超时时间是 10s,后台广播超时是 60s,这类超时没有提示框弹出。

Read More

启动速度优化

启动流程

应用的启动流程如下:

  • SystemServer 负责应用的启动流程调度、进程的创建和管理、 窗口的创建和管理(StartingWindow 和 AppWindow) 等
  • 应用进程被 SystemServer 创建后,进行一系列的进程初始化、 组件初始化(Activity、Service、ContentProvider、Broadcast)、 主界面的构建、内容填充等
Read More

adb工具

查询设备

1
2
3
4
5
adb devices
List of devices attached
emulator-5554 device
emulator-5556 device
emulator-5558 device

将命令发送至特定设备

1
2
adb -s serial_number command
adb -s emulator-5556 install helloWorld.apk

Read More