2

So I manually set the orientation in the onCreate to portrait in my app:

@Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

but I want to change (force) the layout back to landscape when I exit the application. Currently, if my device is locked in landscape and it changes to portrait mode when the app is started I want to be able to go back to landscape. And also vice versa, on onResume I want it to go back to portrait. Is there any way to do this?

EDIT: here is where I try to manually set the orientation back to landscape when I exit the application, but the orientation does not change. When I boot the kernel image its default is landscape orientation but when I change the orientation within an app, the orientation sets it globally on application menu and home screen.

@Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);
        savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
        myVideoView.pause();
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        position = savedInstanceState.getInt("Position");
        myVideoView.seekTo(position);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Log.d(CLASS_NAME, "-- ON DESTROY --");
    }

    @Override
    public void onPause() {
        super.onPause();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Log.d(CLASS_NAME, "-- ON PAUSE --");

    }

    @Override
    public void onStop() {
        super.onStop();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Log.d(CLASS_NAME, "-- ON STOP --");
    }
Eric Reyna
  • 181
  • 1
  • 3
  • 13
  • Possible duplicate of [Force "portrait" orientation mode](http://stackoverflow.com/questions/4885620/force-portrait-orientation-mode) – Chisko Nov 21 '16 at 20:34
  • Unfortunately this does not work. When I exit the app, the screen orientation stays as portrait. – Eric Reyna Nov 21 '16 at 20:37
  • Are you sure your question is regarding your code and not your device's settings? – Chisko Nov 21 '16 at 20:38
  • I'm running off a embedded kernel for Android 4.4. The build does not have a setting for orientation since there is no onboard accelerometer – Eric Reyna Nov 21 '16 at 20:46
  • did you try setting that on `onStop()`? – Chisko Nov 21 '16 at 20:56
  • I tried this: `@Override public void onStop() { super.onStop(); super.onConfigurationChanged(config_change); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); Log.d(CLASS_NAME, "-- ON STOP --"); }` – Eric Reyna Nov 21 '16 at 20:58
  • Could you edit your question with more relevant code and context of what happens? Also noting that you are running a custom build is important and some info about it would be useful. The comments are no place to do this. – Chisko Nov 21 '16 at 20:59
  • Running an ARM Linux-3.10.53 Kernel Image for the Freescale i.mx6qSabreLite board – Eric Reyna Nov 21 '16 at 21:07

0 Answers0