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.
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.
Your Answer
Think you can help? Login to answer this question!