Android 8.1 screen orientation issue: flipping to landscape a portrait screen

前端 未结 10 1612
迷失自我
迷失自我 2020-12-01 03:35

I have all activities in portrait mode except the one that I use to play a video that is always landscape. I found that on Android 8.1 every time I open the video activity a

10条回答
  •  失恋的感觉
    2020-12-01 04:04

    from Narmi's answer:

    When you will back to Activity A from Activity B and if you know the screen's orientation of the Activity A, so set the screen orientation into the ondestroy of Activity B.

    you have to detect if activity is destroying from configuration change, so add field isConfigurationChanged = false, then on onSaveInstanceState method turn it to true and on onDestroy method add this:

    @Override
    protected void onDestroy() {
        if(!isConfigurationChanged)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        super.onDestroy();
    }
    

提交回复
热议问题