how to define the screen orientation before the activity is created?

一世执手 提交于 2019-12-25 05:37:10

问题


I defined my activity to only be in portrait mode by : android:screenOrientation="portrait"

When I take a picture with the camera function via intent, take this picture in landscape mode and turn the screen to portrait mode when saving it, i return to my activity again. What I dont understand is, that my activity for a short time is in landscape mode, is destroyed and then built again in portrait mode... as my onCreate ond onRestore functions need some time, the waiting time for the user is doubled...

Is there a workaround or something else?


回答1:


You can also register your activity to explicitly handle any orientation changes by adding android:configChanges="orientation" to the activity definition and then overriding the onCofigurationChanged method in your activity like this:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

I'm not sure if it would help with your specific problem, but I remember doing this when I wanted an activity to only display in portrait mode. Let me know if it helps :)




回答2:


Add android:configChanges="orientation" to your <activity> tag. This way the activity will not be recreated on orientation change, but will just receive a callback onConfigurationChanged which you can ignore.



来源:https://stackoverflow.com/questions/6772765/how-to-define-the-screen-orientation-before-the-activity-is-created

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