如何分析Activity被relaunch原因

第一阶段

1. 先确定event log 中relaunch的时间点

108-11 15:40:11.327  1000  1709  4746 I wm_relaunch_resume_activity: [0,133396621,3,com.android.settings/.ProvisionSetupChooseLockPattern]

2. 往前查找对应event log中configuration_changed 相关log

附近时间点往前没找到,请前往下面第二阶段

108-11 15:40:11.051  1000  1709  4746 I configuration_changed: 4

3. 根据2中config 数值转换为16进制,在attrs_manifest.xml 中找到对应的config名称

1 上面的4转换为16进制是0x0004,对应android功能清单文件中的locale
 
2 <flag name="locale" value="0x0004" />

4. 在功能清单文件中配置规避Activity重启

配置后没生效,请前往第三阶段

1        <activity
2                android:name=".XXXActivity"
3                android:configChanges="locale"/>

第二阶段

如果relaunch的页面在config发生改变时不在前台,则会在该页面再次resume时触发Activity的relaunch

1. 不看时间往前搜索最近一个configuration_changed(或者system log搜索Config changes= 看得会更清楚详细)

1// config发生在2min前
 
208-11 15:40:11.051  1000  1709  4746 I configuration_changed: 4
 
3// 再次resume该页面
 
408-11 15:42:04.763  1000  1709  3335 I wm_set_resumed_activity: [0,com.android.settings/.SetUpNewFingerprintInternalActivity,resumeTopActivity]
 
5// 同一system server线程触发relaunch
 
608-11 15:42:04.770  1000  1709  3335 I wm_relaunch_resume_activity: [0,88191110,3,com.android.settings/.SetUpNewFingerprintInternalActivity]

2. 重复第一阶段的3 、4操作

第三阶段

配置后没有生效,仍然发生页面的relaunch

1. 确定配置是否生效

目标Activity未被finish前执行 adb shell dumpsys activity a >a.txt

查看目标Activity的configChanges 数值是否与预期一致,确定Rom中是否携带对应的修改。

  * Hist #4: ActivityRecord{541b086 u0 com.android.settings/.SetUpNewFingerprintInternalActivity t3}​
          packageName=com.android.settings processName=com.android.settings​
          launchedFromUid=1000 launchedFromPackage=com.android.provision launchedFromFeature=null userId=0​
          app=ProcessRecord{74745ed 16242:com.android.settings/1000}​
          Intent { cmp=com.android.settings/.SetUpNewFingerprintInternalActivity }​
          ........
          configChanges=0xfa7​
          neverSandboxDisplayApis=false​
          alwaysSandboxDisplayApis=false​
          areBoundsLetterboxed=false

2. 查看是否有遗漏的其他的config 改变

执行 adb shell wm logging enable-text WM_DEBUG_CONFIGURATION 命令后再次复线问题并抓取bugreoprt

3. 按照第一阶段的1、2找到对应的时间点,并在main log中查找“allChanges”

 
108-11 15:42:04.763  1000  1709  3335 I wm_set_resumed_activity: [0,com.android.settings/.SetUpNewFingerprintInternalActivity,resumeTopActivity]
 
208-11 15:42:04.770  1000  1709  3335 V WindowManager: Configuration changes for ActivityRecord{541b086 u0 com.android.settings/.SetUpNewFingerprintInternalActivity t3}, allChanges={CONFIG_LOCALE, CONFIG_LAYOUT_DIRECTION}
 
308-11 15:42:04.770  1000  1709  3335 I wm_relaunch_resume_activity: [0,88191110,3,com.android.settings/.SetUpNewFingerprintInternalActivity]

4. 重复第一阶段的3、4操作添加遗漏的configChanges