There is an MP that should work and only works in portrait mode. Can I carelessly declare in the manifest

android:configChanges="orientation|screenSize" 

to avoid recreating the Activity in a rather rare but unpleasant case:

The user turns off the device screen on the current Activity , changes the orientation and turns it on.

Judging by https://developer.android.com/guide/topics/manifest/activity-element.html and other resources, this should be avoided.

    1 answer 1

    This is best avoided because the view will not be recreated using the qualifier you need (layuot-land, etc.). If you know for sure that you have all the resources that are the same for different orientations, then you can safely use configChanges . There are unusual situations when without this in any way.

    However, if your application only works in a portrait, you can specify it in the manifest

     android:screenOrientation="portrait" 

    And do not worry about turning the screen.

    • the fact of the matter is that it is written. But here's the trouble - when you turn on the device in non-portray mode, the recreation and redrawing of the activity / fragment still happens - abbath0767
    • @ abbath0767 I think the key point here is that the user turns off the device screen . Nevertheless, the system does not guarantee that your Activity will not be killed when the screen is turned on / off and when the application is minimized / expanded. Not sure that configChanges should help with this. - lllyct
    • By the way, I checked it myself. On a powerful device without the don't keep flag flag, the activity is not recreated without configChanges, but this does not mean that it will not always be recreated. Depends on the power device, the duration of the shutdown, etc. The system itself makes a decision about nailing or not nailing aktivnost. - lllyct
    • Thanks for the comment, did not know that it depends on the hardware device. Probably you are right and we will work with standard methods. True, I still don’t understand why adding this flag to the project doesn’t reproduce the problem and doesn’t require additional processing of the device’s configuration changes (after adding all the saveRetainInstance methods, nothing fell and it worked as if the activity was not recreated, like all internal fragmettes) - abbath0767