0
votes

I am facing a small problem.In my application i am trying to have portrait and landscape view for audio streaming app in which i am using custom view to show visualizer on layout. I have created two folder one is layout and another is layout-land and i put xml into that with same name but change in code for size,width.

Also i have added `android:configChanges="orientation|keyboardHidden" But when i rotate my handset , orientation change take place to landscape but xml is displayed from default layout only.. it doesn't take layout-land xml to show landscape mode.

as i am using custom view to display visualizer on my both land and port xml so my mediaplayer object is connected to XML and when i change orientation than media player object get recreated and start playing music

2

2 Answers

2
votes

Please refer developer.android.com It specifies:

android:configChanges Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

Since you have specified android:configChanges="orientation", it means that your activity itself will handle orientation changes from onConfigurationChanged().

Remove android:configChanges from manifest. Your problem will be solved.

0
votes

When you write,

android:configChanges="orientation|keyboardHidden"

your activity is not recreated, so its not loading the xml from the layout-land folder. If you want to load xml from layout-land folder you have to manually change the overriding onConfigurationChanged() and handling the config changes yourself. Check out my answer here.