I am having issues with orientation change in multi-window mode. The activity doesn't restart on changing orientation when the window size is 2/3 (in multi-window mode) in a tablet device. My layout looks improper due to that.
The activity restarts properly while changing orientation when the window size is 1/2 or 1/3 the display size in multi window mode. I tried and confirmed this with Nexus 7 and Pixel C devices in (Android Studio) Emulator with Oreo and Pie images.
My app is targeting Oreo 8.1 and I am not using 'android:configChanges' or 'android:screenOrientation' in the manifest.
Note that 2/3 window size is not square and there is a small change in screen size in both orientation and if the orientation change doesn't trigger than the screensize change should trigger activity restart.
Steps to reproduce:
Am I missing something which is causing this issue? or is this a bug or something else? How can I make my activity restart in this case?
An interesting question, I never knew that there are exceptions to the orientation change process. I was able to reproduce the problem with a Pixel C emulator(Android 8.1) and an app targeting API level 26.
I suppose your screen is not just another list because in this case the difference of 12 pixels (1688 vs. 1676 if I can trust LayoutInspector) would not matter, so I wanted to add an observation which may be helpful:
My app contains a custom View
, and from the logs I can see that its methods onMeasure()
and onLayout()
are called even if the Activity
'sonCreate()
is not. So this is where you can step in and do some fine tuning.
Another option is to force the Activity
to be recreated. You could do so by calling the Activity
method recreate()
(documented here) as soon as you detect that the screen dimensions have changed. To keep track of the screen size changes, you can create a custom ViewGroup
overriding onLayout()
and use this as the root of your Activity
's layout file.