Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16146] Android: orientation lock in Android manifest buggy when screen locked

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.2.0
Fix Version/sn/a
ComponentsAndroid
Labels3.1.3.GA, 3.2.0, android, orientation, orientationmodes
ReporterMark Mokryn
AssigneeUnknown
Created2013-12-25T19:34:13.000+0000
Updated2018-02-28T20:03:56.000+0000

Description

I am using the android:screenOrientation="portrait" property to lock app activities into portrait mode. However, I noticed that the app was behaving very strangely when coming out of screen lock in landscape mode. Upon investigating, I realized that the window was being closed and re-opened when the screen lock went into landscape mode. Run the app below, and here is how to reproduce. 1. Open the app - it will run in portrait mode as expected. Rotating the tablet has no effect - good. 2. With the app active, lock the screen. 3. Rotate the tablet to landscape mode, and wait for the screen lock to adjust accordingly. 4. Unlock the screen in landscape mode: you will see that the window was opened multiple times, which will totally screw up application logic in most cases. Note that the window is instantiated only once, but the close and open events fire multiple times. app.js:
Ti.API.info('This will print only once, as expected');
var win1 = Titanium.UI.createWindow({  
    backgroundColor:'#fff',
    modal: false // ensure heavyweight window in all SDKs
});
var numOpens = 0;
var label1 = Titanium.UI.createLabel({
	color:'#999',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width: Ti.UI.FILL,
	height: Ti.UI.SIZE
});

win1.add(label1);
win1.addEventListener('open', function() {
	numOpens++;
	label1.text = 'Window was opened ' + numOpens + ' times';	
});

win1.addEventListener('close', function() {
	Ti.API.info('window was closed');
});
win1.open();
Android section in tiapp.xml:
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application android:debuggable="false"
                android:icon="@drawable/appicon" android:label="orient" android:name="OrientApplication">
                <!-- TI_APPLICATION -->
                <activity android:configChanges="keyboardHidden"
                    android:label="orient"
                    android:name=".OrientActivity"
                    android:screenOrientation="portrait" android:theme="@style/Theme.Titanium">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
                <activity android:configChanges="keyboardHidden"
                    android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
                <activity
                    android:configChanges="keyboardHidden" android:screenOrientation="portrait"
                    android:name="org.appcelerator.titanium.TiTranslucentActivity" android:theme="@android:style/Theme.Translucent"/>
                <activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
                <service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"/>
            </application>
        </manifest>
    </android>

Comments

  1. Ritu Agrawal 2013-12-26

    [~mokesmokes] TIMOB-8912 appears to be related to this issue. There was a work around suggested in that ticket and I am curious if the same work around works for you. Can you please try it and let us know? From TIMOB-8912 --------------- This appears to be caused when setting the min SDK level to 13 or higher. Android added a new configChanges flag which if not set will cause a restart of the activity. A workaround is to customize the manifest and include "screenSize" and "smallestScreenSize" in the android:configChanges options. We can't generate these yet in the default manifest since we need to support API level 8.
  2. Mark Mokryn 2013-12-26

    The workaround does not seem to work: I added the following to the manifest (tested on 3.2.0.GA):
       <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
       
    And also added "|screenSize" to the configChanges in all activities - and the bug persists. In any case, the text in the old bug report is wrong. The "screenSize" and "smallestScreenSize" changes *will never* cause an activity restart. In API 12 and earlier these changes will always cause onConfigurationChanged() to be called, and in API13 and later this function is called only when these attributes are set in configChanges. Please see the [android docs](http://developer.android.com/guide/topics/manifest/activity-element.html#config). Bottom line - with this bug it seems impossible to prevent multiple window close and open events when the portrait-locked window is open, the screen is then locked, and rotated to landscape, so it's a serious issue which will cause almost all orientation locked apps to go bonkers.
  3. Ritu Agrawal 2014-01-06

    [~mokesmokes] I am curious how do you get your screen lock to display in both portrait and landscape modes. My Android phone screen lock remains in portrait mode even if I rotate it to landscape mode. There are few applications on the Google Play that allows you to achieve this but it does not appear to be a factory setting.
  4. Mark Mokryn 2014-01-06

    Hi Ritu, My phones also screen lock in portrait mode only, but note this bug occurs on a Samsung Tab 2 tablet. I'm guessing most, perhaps all tablets will screen lock in both modes.
  5. Ritu Agrawal 2014-01-06

    Thanks, Mark. I will try to reproduce it on a Samsung tablet.
  6. Mark Mokryn 2014-01-06

    BTW - I'm guessing that if you lock the app in landscape mode on a phone (in Android manifest, etc), the portrait screen lock on your phone will cause the same bug.
  7. Ritu Agrawal 2014-01-08

    Moving this ticket to engineering as I can reproduce the issue with the provided test case on Samsung Tab 2 tablet. This issue occurs only when the screen is locked and unlocked and that results in lock screen to switch from portrait mode to landscape mode.

JSON Source