Prevent application restart when orientation changes

I have a canvas, and it changes when the orientation changes. This is a custom canvas not provided by android.

When you change the layout of the screen, the application state and (all viewing states) gets reset. I changed the screen orientation to portrait only; it keeps the screen configuration unchanged, but the application restarts again.

I checked the documentation and found that the activity was destroyed and restarted again when the orientation changed. Savestate () cannot save and load raster data or any big data that is required on my regular canvas.

I checked the documentation again and found the section "Runtime Handling", which is mentioned in onConfigurationChanged (), which is called when a certain configuration change occurs, which in my case is "orientation". This method prevents a restart and leaves the developer how this configuration change should be implemented. In the last paragraph it was even mentioned that if I did not apply this method, this would cause the activity to be skipped onRestart () and not do anything. I set the manifest file as

android:screenOrientation="portrait"
android:configChanges="orientation"

And I do not implement onConfigurationChanged (). But that doesn't help either. I do not know why. It seemed to me very useful.

, , . , , , . , . , , , , .

P.S. , . . , , . , .

+3
3

AndroidMenifest.xml

<activity
            android:name="MyActivity"
            android:configChanges="orientation|keyboard|keyboardHidden"
            android:screenOrientation="sensor" />
+7

:

android:configChanges="orientation|screenSize|keyboardHidden"
+1

AndroidManifest ScreenOrientation. , , , :

Android: screenOrientation = ""

, , :

Android: screenOrientation = ""

, . : Android, . : : configChanges = " | keyboardHidden"

0

All Articles