I have some API calls on my activity and different UI design for portrait and landscape mode.
I have added the below code in the manifest to avoid the activity recreation on mode change. But with the below code, will not support a different UI. So with this while changing the mode from one to another, the same UI will be displayed for both cases.
android:configChanges="orientation|screenSize|keyboardHidden"
Tried by removing this code, then that UI is working as expected but activity is recreating on every rotation. I want to avoid that as well. Please suggest a better solution for this.
And my activity configure change is handled like below
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
}
}
}