Frempe
Frempe

Reputation: 267

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?

Upvotes: 0

Views: 546

Answers (2)

Xion
Xion

Reputation: 22770

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.

Upvotes: 0

stephendnicholas
stephendnicholas

Reputation: 1830

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

Upvotes: 1

Related Questions