Reputation: 140
I have an activity that handles 2 modes of display :
I have only 1 activity to handle the 2 modes with :
isFullscreen()
that indicates either the Activity
is in fullscreen mode or normal mode.changeMode()
calls setContentView()
to switch the XML layout proper to the current modeandroid:configChanges="screenSize|orientation"
to let the Activity
handle configuration changeonConfigurationChanged()
.I've tried this :
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (isFullscreen) {
super.onConfigurationChanged(newConfig);
} else {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
but in this case : the screet does not rotate in any mode (not even in fullscreen mode, with isFullscreen()
et to true)
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (isFullscreen) {
super.onConfigurationChanged(newConfig);
} else {
}
}
But I got Super Not Called exception
or something like that (I was thinking if i don't call super in the case of normal mode, it would not rotate the screen)
And finally, I've tried this :
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (isFullscreen) {
super.onConfigurationChanged(newConfig);
} else {
newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
super.onConfigurationChanged(newConfig);
}
}
Upvotes: 2
Views: 1392
Reputation: 839
when you are toggling fullscreen call this don't do it in onConfigurationChanged
code:
if(isFullscreen){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Upvotes: 2