I am using this code to detect layout orientation changes but the following code uses the same portrait layout instead of layout kept in layout-land.
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
If you override onConfigurationChanged method then onCreate method does not called while Screen Orientation changed. Your activity is not restarted. That’s why you are getting same layout.
You need to call setContentView(R.layout.your_layout) in onConfigurationChanged method.