I tried searching for a clear answer but could not find it so asking it here. Apologies if this is a nOOb question.
My question is Does Android Cache the view inflation outside the scope of the activity?
I wrote a sample app in which there are 2 activities
Activity A Activity B
A just has a button that launches B. B has a fairly complex layout.
B has a view stub and I timed theViewStub inflation (that basically renders the whole layout).
When I timed how much time it takes for B's layout to inflate. First time It took roughly 100ms. Further inflations took 15-20 ms. Weird part was after few iterations, randomly B again takes 100+ ms to inflate.
I also verified that my complex activity (B) is getting destroyed and created again (as I hit back from B and launch B again from A)
I could not find anything in the Android code base which could explain me why this is happening.
Could someone please tell me where is this caching taking place.
Here are logs of the ComplexActivity onCreate and onDestroy. I am using back press to destroy the activity
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.