开发者

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

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?


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 :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜