1

I am beginner in Android Development. I have two layouts (portrait and Landscape) for a single activity. In my layout, I have a VideoView and a custom Media player. whenever I rotate the phone screen the video begins from start for this issue and saving the data on screen rotation I have added this in my manifest file

 android:configChanges="keyboardHidden|orientation|screenSize"

After adding this in my manifest, my video is playing normally but my activity is picking only Portrait layout whenever I rotate the screen.

Mk Kamal
  • 191
  • 1
  • 7
  • Possible duplicate of [How to keep playing video while changing to landscape mode android](https://stackoverflow.com/questions/11031295/how-to-keep-playing-video-while-changing-to-landscape-mode-android) – Gowthaman M Aug 16 '18 at 11:39
  • whenever you apply `screensize` then you have to manage on your own in method `onConfigurationChanged`. In This case `onCreate()` calls only once. You have to reshape your activity as per your requirement. If you not apply `screensize` then your activity created again – Devil10 Aug 16 '18 at 11:46
  • @GowthamanM my issue is not about saving the video state on screen rotation but picking the same mode (portrait) of layout evertimes. – Mk Kamal Aug 16 '18 at 11:53

1 Answers1

0

use below code when orientation change

        switch (getResources().getConfiguration().orientation) {
                case Configuration.ORIENTATION_PORTRAIT:
                    setContentView(R.layout.control_layout_vertical);
                    break;
                case Configuration.ORIENTATION_LANDSCAPE:
                    setContentView(R.layout.control_layout_horizontal);
                    break;
            }
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54