Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10863] Android: Application restarts when orientation changes and targetSdkVersion is 13 or higher

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-08-06T19:01:40.000+0000
Affected Version/sRelease 2.1.2
Fix Version/sRelease 2.1.3, Release 3.0.0, Sprint 2012-19 Core, 2012 Sprint 19
ComponentsAndroid
Labelscore, module_orientation, qe-testadded, triage
ReporterBill Dawson
AssigneePing Wang
Created2012-09-12T03:17:46.000+0000
Updated2017-03-21T23:52:36.000+0000

Description

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.

Fail Case / Test Case

* Create a Titanium mobile app. * Change its tiapp.xml so that the section looks like this:
<android xmlns:android="http://schemas.android.com/apk/res/android">
	<manifest>
		<uses-sdk android:targetSdkVersion="13" android:minSdkVersion="8"/>
	</manifest>
</android>
* Replace the app.js with this:
var win = Titanium.UI.createWindow({  
    title:'Root Window',
    backgroundColor:'#fff',
	exitOnClose: true
}),
btn = Ti.UI.createButton({
	title: "Open Heavyweight Window",
	left: "16dp", right: "16dp", height: "48dp",
	bottom: "16dp"
});

win.add(Ti.UI.createLabel({
	text: "This is the root window",
	color: "#000",
	height: "48dp"
}));

win.add(btn);

btn.on("click", function() {
	var w = Ti.UI.createWindow({
		backgroundColor: "#f00",
		title: "New Activity",
		fullscreen: false
	});
	w.add(Ti.UI.createLabel({
		text: "This is a new Activity",
		height: "48dp",
		color: "#fff"
	}));
	w.open();
});

win.open();
* 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.

Comments

  1. Max Stepanov 2012-09-14

    Backport PR https://github.com/appcelerator/titanium_mobile/pull/2960
  2. Satyam Sekhri 2012-09-17

    Application does not close on orientation change Verified on: Titanium Studio: 2.1.2.201208301612 Titanium SDK: 2.1.3.v20120915120319 Android Device: LGP970 (v2.2.2), Samsung Note (v2.3.6), Samsung Galaxy Tab (v3.2), Galaxy Nexus (v4.0.2)
  3. Manoj Kumar 2013-06-04

    I'm facing same issue with Titanium SDK 3.1.0 GA with following on tiapp.xml. Target SDK version on 16 - application restarts on orientation changed. http://schemas.android.com/apk/res/android"> 8
  4. Manoj Kumar 2013-06-04

    The above issue i mentioned is tested with HTC ONE S - Android 4.1.1
  5. Michael Gangolf 2013-06-19

    11 SDK 3.1.1, Application is restarting, too
  6. Michael Gangolf 2013-08-03

    Still restarts in 3.1.2 RC1 tiapp.xml {noformat} http://schemas.android.com/apk/res/android"> 8 {noformat} and {noformat} http://schemas.android.com/apk/res/android"> 11 {noformat} will show the white window again after rotating the example app in the description
  7. Ping Wang 2013-08-06

  8. Michael Gangolf 2013-08-06

    nice, thank you! That worked
  9. Lee Morris 2017-03-21

    Closing ticket as fixed.

JSON Source