Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ICS Launcher 4.0.x cannot keep screen orientation

I've got a strange case for Android ICS Launcher 4.0.x.

Pre-condition:

  • A ICS device with root permission

  • Download Android ICS Launcher 4.0.3/4 source code (to modify and run)

Procedure:

  1. Go to market (Play Store), download "Go Task Manager"

  2. Open Widgets tab on Launcher, find "Mem Optimize", drag to Home screen (workspace)

  3. Download and install "Fruit Ninja"

  4. Create "Fruit Ninja" shortcut next to "Mem Optimize" widget on Home screen.

  5. Execute "Fruit Ninja" and keep your phone in LANDSCAPE (hold it in your hand in this position, don't change this)

  6. On menu screen of "Fruit Ninja", slice "Exit" , select "Yes"

  7. Now back on Launcher Home screen, touch on "Mem Optimize" widget

Current Result:

  • After step 7, the screen is rotated to LANDSCAPE for a while and return to PORTRAIT.

Expectation:

  • After step 7, the screen should be kept in PORTRAIT.

My Tries (modify Launcher ICS source code):

  • Add to "Manifest.xml": android:screenOrientation="portrait" => still can't fix the problem.

  • Handle configuration change, android:configChanges="orientation|screenSize" => still can't fix the problem.

  • Use: setRequestedScreenOrientation(PORTRAIT) => still can't fix the problem.

What I've tried worked on Android 2.x; however, from 4.0.3+ , somehow it's not working as expected. Does anyone have any idea about this?

like image 415
Pete Houston Avatar asked May 17 '12 02:05

Pete Houston


1 Answers

The problem is not in the Launcher. The problem is that a single configuration ( and that includes the orientation) is shared among all activities on the phone.

So if you have an activity that set the orientation to Landspace,e.g. Camera ( this is classical example where I work), this will "make" all the other activities to be on landscape too, because as I said that information is unique in system and shared among all.

This happens since the beginning of Android albeit sometimes you will not notice that because the changes are pretty fast.

To check what I am saying do the follow. Write an activity with a dialog theme such as @android:style/Theme.Holo.Dialog, so it won't cover the entire screen and you'll still be able to see the activity that was bellow. That activity must have a fixed orientation. Let's say that you set it to landscape. Then use am start on Android shell to be able to start the activity you have just created on top of any other activity. You'll see that no matter the orientation that previous activity had, as soon as you launch you test activity, the previous activity will assume the same orientation than your test activity. When you hit back, the previous activity will restore the orientation. But sometimes it might take a while, so you see things like your current result.

like image 116
André Oriani Avatar answered Oct 22 '22 14:10

André Oriani