Android child activity and orientation lock

孤人 提交于 2019-12-24 01:01:24

问题


I've done quite a bit of searching and trial/error testing in trying to get my application fixed in portrait mode however I'm stumped on this one.

Background: This application has a main activity which shows static images with various transition effects. It uses a sub activity to show a MediaPlayer because the SurfaceView (required to show the movie clip) cripples the display performance of the still image transitions.

Both activities are locked in portrait mode and this seems to work pretty well for the most part. My issue is when the child activity finishes and I physically have the device in landscape position it temporarily switches to landscape mode then back into portrait mode. In doing so I see the arrows on the screen, etc, and I don't want this.

Here's dump from logcat:

D/cursor ( 1357): cursor_rotate 0
I/WindowManagerService( 1357): Setting rotation to 0, animFlags=1
I/ActivityManager( 1357): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=1/1/2 nav=1/1 orien=2 layout=35 uiMode=17 seq=1726}
D/main_activity( 6851): onActivityResult: 0
D/child_activity( 6851): surfaceDestroyed called
D/cursor ( 1357): cursor_rotate 3
I/WindowManagerService( 1357): Setting rotation to 3, animFlags=1
I/ActivityManager( 1357): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=1/1/2 nav=1/1 orien=1 layout=35 uiMode=17 seq=1727}
D/StatusBarPolicy( 1357): ro.wmt.ui.portrait.hide.capbtn = 1
D/StatusBarPolicy( 1357): wm.getRotation = 3
D/StatusBarPolicy( 1357): ro.wmt.ui.portrait.hide.capbtn = 1
D/StatusBarPolicy( 1357): wm.getRotation = 3

The only two lines I want to see are in bold, everything else I want to eliminate. Occasionally, the switch is seamless depending on timing so I'm guessing there's some sort of race condition?


回答1:


You can set this on the Android Manifest, just like this answer suggested:

<activity 
    android:name=".MyActivity" 
    android:screenOrientation="portrait"
    android:configChanges="orientation|keyboardHidden|keyboard"/>`



回答2:


You can disable orientation changes in your Activities. I asked a similar question here.

You can call:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

to disable orientation changes.



来源:https://stackoverflow.com/questions/7654585/android-child-activity-and-orientation-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!