Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-16146

Android: orientation lock in Android manifest buggy when screen locked

    Details

      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>
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mokesmokes Mark Mokryn
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-18153
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code