Affects Version/s: Release 2.1.2
Titanium 2.1.2, Titanium Studio version is irrelevant, Desktop OS is irrelevant, Android device/emulator with Android 3.2 or higher.
If an app targets Android api level 13 (Honeycomb MR2, aka Android 3.2) or higher, the screenSize config change (which occurs when the orientation changes, for example) is not handled automatically by Android, and thus causes (by default) an activity restart (cf http://developer.android.com/reference/android/R.attr.html#configChanges). We don't accept activity restarts in Titanium and instead just restart the app (i.e., close all activities and restart the root activity). Traditionally we overcome the problem with orientation changes using the configChanges attribute's orientation value in our Activity entries in AndroidManifest.xml. But now screenSize also needs to be handled.
So if an app developer changes their tiapp.xml to add android:targetApiLevel="13" (or higher) – which is something they would do to get an ICS look-and-feel, for example, and will therefore occur more and more – their app will restart (on 3.2 or higher devices) when the orientation changes because of the unhandled screenSize. So we need to add screenSize to the configChanges in AndroidManifest.xml Activity entries. However, it's not that easy: to do that, we need be sure to also build against api 13 or higher, since building against an older version will cause aapt to fail if screenSize is in there; this fails the application build. So a somewhat clever solution is required.
- Create a Titanium mobile app.
- Change its tiapp.xml so that the <android> section looks like this:
- Replace the app.js with this:
- Run the app on 3.2 or higher device.
- After the app loads, click the "Open Heavyweight Window" button.
- After the red window opens, turn the device to a different orientation (i.e., from portrait to landscape or vice-versa).
- In the fail case, the app will actually close completely and re-open back at the first (white, not red) window. When testing the fix, the app should not close and the red window should still be showing.
- Also build and run the app on a pre-3.2 device (a 2.3 phone, for example) to be sure nothing is broken for older versions of android.