Inconsistent Portrait Mode Locking

You must Login before you can answer or comment on any questions.

My app has a handful of windows. After each of those windows is created, I have code whose intent is to lock those windows in portrait mode:

var win = Ti.UI.createWindow({ ... });
win.orientationModes = [ Ti.UI.PORTRAIT ];

I still can't believe that there isn't a more universal way of doing this for Android, but that's a gripe for another day. :-) For now, this is mostly working. I'm hoping someone here can help me remove the mostly qualifier.

The app opens with a tab group containing 4 tabs. If I rotate my device as soon as the default active tab is loaded, the layout rotates as well. Oops. In fact, if I go immediately to any of those tabs and rotate my device, the layout rotates. More oops.

However -- and this is the fun part -- if I relaunch the app and jump first to a secondary window, one loaded from one of the tab windows, and rotate my phone, no display rotation. Yay! Now I jump back to any of the tab windows, the ones that were rotating before, they no longer rotate.

Wat?!

That's the pattern I think I'm seeing right now. Anyone seen this before? I'm guessing that it's a tab group thing, but I don't see any orientation accessors in the API. Any guidance would be much appreciated.

Thanks.

— asked 9 months ago by Rob Wilkerson
2 Comments
  • I still lock mine in the androidManifest

    — commented 9 months ago by Stephen Feather

  • I tried one custom manifest solution, but at the end of the day, I still have to make the change for every activity, but then, even worse, remember to do the same for any activities that may get added later. It's easier to remember, I think, if it's just part of the window creation process.

    — commented 9 months ago by Rob Wilkerson

1 Answer

Accepted Answer

Android orientation is tied to the activities, as Rob noted. In the tiapp.xml (or AndroidManifest), you're essentially defining what orientations the app could take. In your JavaScript, you have the opportunity to specify which orientation a specific window will support. As I think you've found, one is essentially a subset of the other.

This is handled similarly on iOS. In the tiapp.xml you specify the orientations the app could take; in your JS you specify the orientation for a window. The syntax is a whole lot simpler, of course, because you just add (or remove) the XML tags.

I suggest you manage the app's orientation as late as possible in the dev cycle. Alternatively, you should periodically update the tiapp.xml by removing all the <manifest> stuff, regenerating the AndroidManifest.xml, and moving that content back to tiapp.xml.

— answered 9 months ago by Tim Poulsen
answer permalink
3 Comments
  • Okay, so if I understand correctly, it sounds like my only option is to open build/android/AndroidManifest.xml, copy the activity contents to the android &gt; manifest parent in my tiapp.xml file and make the orientation changes to those lines. And then, of course, maintain this over time. Does that sound about right?

    Thanks again.

    — commented 9 months ago by Rob Wilkerson

  • That's the "preferred" method because it keeps all your configuration in one place -- the tiapp.xml file. You can also use a custom manifest by copying build/android/AndroidManifest.xml to platform/android/AndroidManifest.xml. Again, you'd need to maintain that over time. And you'd have to manually merge any changes (such as version numbers) from tiapp.xml to your custom manifest file.

    — commented 9 months ago by Tim Poulsen

  • Thanks, Tim. It's a little more pain than I had hoped, but it does seem to be working to fix the orientation.

    — commented 9 months ago by Rob Wilkerson

Your Answer

Think you can help? Login to answer this question!