记一个有可能引起reportSizeConfigurations: ActivityRecord not found for: Token的问题,这两天听云上看见有个reportSizeConfigurations: ActivityRecord not found for: Token的崩溃,分析了一天时间终于找到了引起原因,特别记录一下。
当Activity设置了android:noHistory="true"时且在启动这个Activity时主线程中有耗时操作,且此时用户正好把应用回到后台,就会发生reportSizeConfigurations: ActivityRecord not found for: Token,这个耗时时间根据不同品牌的手机有差异。
源码如下:
@Override
public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration,
int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " "
+ horizontalSizeConfiguration + " " + verticalSizeConfigurations);
synchronized (this) {
ActivityRecord record = ActivityRecord.isInStackLocked(token);
if (record == null) {
throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not "
+ "found for: " + token);
}
record.setSizeConfigurations(horizontalSizeConfiguration,
verticalSizeConfigurations, smallestSizeConfigurations);
}
}
从源码上看是ActivityRecord为null,通过token找到对应的ActivityRecord,我们知道 ActivityRecord是用来记录Activity,在ActivityThread发出了启动某个Activity的Message后如果此时回后台,恰巧应用主线程又有耗时操作,Activity被回收了,导致ActivityRecord找不到了,就会报reportSizeConfigurations: ActivityRecord not found for: Token。