According to Android guide "screenSize" changes when user rotates the device, why isn't "orientation" value enough to indicate that?
2 Answers
The screenSize
configuration change doesn't mean that the physical screen has been changed, but it means that the dimensions of the logical screen have. For instance, the DisplayMetrics.widthPixels
value will be much larger after a rotation from portrait to landscape.
One thing to consider is that both the screenSize
configuration change type and the smallest width and available width resource qualifiers were both added in API level 13. The available width of your screen changes when you rotate your device, so it makes sense that this would be flagged as a "screen size" change.

- 52,661
- 6
- 95
- 123
you can fix this in your Manifest
just add this line
android:configChanges="orientation|screenSize"
If you create a different XML for landscape don't use the android:configChanges="orientation|screenSize"
tag for that activity.

- 12,319
- 5
- 67
- 77
-
Adding the `android:configChanges` attribute in your manifest in order to prevent activity destruction and recreation by the framework is a bad idea, and should only be done by experts who know exactly what they're getting into. Average users are dramatically better off simply learning how to work within the android activity lifecycle. – Ben P. Jan 29 '18 at 03:12
-
hi @BenP. thanks for the advice :) ! this is like a workaround and not should be consider safe using it – Gastón Saillén Jan 29 '18 at 03:22
-
If you don't mind can you explain more why is it not safe to use? – Toka A. Amin Jan 29 '18 at 18:26
-
because as i said if you have a different xml for landscape or verticall you will have problem with this, lets say that this just auto adjust the screenSize – Gastón Saillén Jan 29 '18 at 18:28
-
@tokaaliamien The presence of this attribute changes the behavior of your activity during a configuration change. Without the attribute, your activity will be destroyed and recreated (with the new configuration present, allowing automatic reloading of configuration-dependent resources). With the attribute, your activity is not destroyed and recreated, so you have to manually re-load these resources yourself. Additionally, this attribute is mostly used to prevent state loss during rotation, but will do nothing to prevent state loss when the user backgrounds your app etc. – Ben P. Jan 29 '18 at 19:33