I've created a simple TabActivity which builds tabs at runtime reading some JSON data. At the moment I'm initializing an empty ListActivity with dummy random items for each tab just to see that changing from tab to tab works and the content doesn't disappear. The actual content for the tabs is stored in a singleton class, so when the tab activities get re-created due to a screen orientation change, they just pull the correct dummy items from the respective list according to an identifier contained in the intent's extras bundle.
Everything works fine. I've put a log on the list activity onCreate method to watch the activities get recreated on screen rotation, and they do. However, there is something strange in that the activity for the first tab is always recreated, even if it is not visible. When I switch to the third or fourth tab and rotate the device, the previous tabs get killed and don't get recreated again, except the first tab. The first tab is always there. Why? I would understand a bug in the code, but the tab activity is copied from a tutorial and the list activity is the same for all tabs. Here are some logs I get:
List created with 1
onConfigurationChanged
List created with 1
List created with 2
List created with 4
List created with 5
List created with 6
onConfigurationChanged
List created with 1
List created with 6
onConfigurationChanged
List created with 1
List created with 6
onConfigurationChanged
List created with 1
onConfigurationChanged
List created with 1
List created with 2
onConfigurationChanged
List created with 1
List created with 2
onConfigurationChanged
List created with 1
List created with 2
List created with 4
onConfigurationChanged
List created with 1
List created with 4
onConfigurationChanged
List created with 1
List created with 4
List created with 5
onConfigurationChanged
List created with 1
List created with 5
onConfigurationChanged
List created with 1
List created with 5
As you can see from the logs, each list activity logs the identifier put in the extras bundle, and does pretty much nothing else. So the application starts and the first tab gets created, then I rotate and switch to the other tabs. Their onCreate method is called. And then the log shows how I'm switching tabs and rotating. Different activities get recreated depending on which tab is visible, but the first one is always there!
Why is the first tab always being recreated? Is this special behavior needed for some reason? I'm seeing this on an HTC Legend API level 7.
UPDATE: I've put some more logs in the TabActivity's loop creating the individual tabs, and it looks like when the first tab is added its activity is always created. Is there any way to avoid this? Maybe create dummy empty tabs and later populate them with the real activities? Some more logs:
onConfigurationChanged
Tab: Saving tab index 3
...
Tab: Adding tab 1
List created with 1
Tab: Adding tab 2
Tab: Adding tab 3
Tab: Adding tab 4
Tab: Adding tab 5
Tab: Setting tab to index 3
List created with 5