我试图寻找一个明确的答案,但找不到,所以在这里问。抱歉,如果这是一个 noOOb 问题。
我的问题是 Android 是否缓存活动范围之外的视图膨胀?
我写了一个示例应用程序,其中有 2 个活动
活动 A 活动 B
A只有一个启动B的按钮。B的布局相当复杂。
B 有一个视图存根,我计时了 ViewStub 膨胀(基本上呈现整个布局)。
当我计算 B 的布局膨胀需要多少时间时。第一次大约花了 100 毫秒。进一步的膨胀需要 15-20 毫秒。奇怪的部分是经过几次迭代后,随机 B 再次需要 100 多毫秒才能膨胀。
我还验证了我的复杂活动 (B) 正在被破坏并再次创建(当我从 B 回击并从 A 再次启动 B 时)
我在 Android 代码库中找不到任何可以解释为什么会发生这种情况的东西。
有人可以告诉我这个缓存发生在哪里。
以下是 ComplexActivity onCreate 和 onDestroy 的日志。我正在使用后按来破坏活动
04-30 13:32:09.879: I/testInflation(19298): onCreate setting up content view
04-30 13:32:09.895: I/testInflation(19298): onCreate content view set. Time took = 15 ms.
04-30 13:32:09.895: I/testInflation(19298): onCreate inflating ui
04-30 13:32:10.004: I/testInflation(19298): onCreate ui inflated. Time took = 108 ms. Total time into method = 123 ms.
04-30 13:32:12.450: I/testInflation(19298): activity destroyed
04-30 13:32:12.903: I/testInflation(19298): onCreate setting up content view
04-30 13:32:12.911: I/testInflation(19298): onCreate content view set. Time took = 13 ms.
04-30 13:32:12.911: I/testInflation(19298): onCreate inflating ui
04-30 13:32:12.926: I/testInflation(19298): onCreate ui inflated. Time took = 13 ms. Total time into method = 26 ms.
04-30 13:32:13.958: I/testInflation(19298): activity destroyed
04-30 13:32:14.379: I/testInflation(19298): onCreate setting up content view
04-30 13:32:14.395: I/testInflation(19298): onCreate content view set. Time took = 11 ms.
04-30 13:32:14.395: I/testInflation(19298): onCreate inflating ui
04-30 13:32:14.403: I/testInflation(19298): onCreate ui inflated. Time took = 11 ms. Total time into method = 22 ms.
04-30 13:32:15.223: I/testInflation(19298): activity destroyed
04-30 13:32:15.622: I/testInflation(19298): onCreate setting up content view
04-30 13:32:15.637: I/testInflation(19298): onCreate content view set. Time took = 11 ms.
04-30 13:32:15.637: I/testInflation(19298): onCreate inflating ui
04-30 13:32:15.645: I/testInflation(19298): onCreate ui inflated. Time took = 13 ms. Total time into method = 24 ms.
04-30 13:32:16.692: I/testInflation(19298): activity destroyed
04-30 13:32:17.934: I/testInflation(19298): onCreate setting up content view
04-30 13:32:17.950: I/testInflation(19298): onCreate content view set. Time took = 11 ms.
04-30 13:32:17.950: I/testInflation(19298): onCreate inflating ui
04-30 13:32:17.965: I/testInflation(19298): onCreate ui inflated. Time took = 18 ms. Total time into method = 30 ms.
04-30 13:32:19.020: I/testInflation(19298): activity destroyed
04-30 13:32:23.825: I/testInflation(19298): onCreate setting up content view
04-30 13:32:23.833: I/testInflation(19298): onCreate content view set. Time took = 12 ms.
04-30 13:32:23.833: I/testInflation(19298): onCreate inflating ui
04-30 13:32:23.848: I/testInflation(19298): onCreate ui inflated. Time took = 11 ms. Total time into method = 23 ms.
04-30 13:32:26.622: I/testInflation(19298): activity destroyed
04-30 13:32:27.145: I/testInflation(19298): onCreate setting up content view
04-30 13:32:27.161: I/testInflation(19298): onCreate content view set. Time took = 15 ms.
04-30 13:32:27.161: I/testInflation(19298): onCreate inflating ui
04-30 13:32:27.231: I/testInflation(19298): onCreate ui inflated. Time took = 69 ms. Total time into method = 85 ms.
04-30 13:32:28.200: I/testInflation(19298): activity destroyed
04-30 13:32:28.645: I/testInflation(19298): onCreate setting up content view
04-30 13:32:28.661: I/testInflation(19298): onCreate content view set. Time took = 11 ms.
04-30 13:32:28.661: I/testInflation(19298): onCreate inflating ui
04-30 13:32:28.747: I/testInflation(19298): onCreate ui inflated. Time took = 91 ms. Total time into method = 102 ms.