Good afternoon in the method

protected void onCreate(Bundle savedInstanceState) { } 

when launching the application, I call the necessary methods for its operation, but I noticed as soon as I turn the device over and over and the main Activity, and with it all the methods that were called earlier are called again as if the application was started again, how can you avoid it? There is an option to block the Activity from turns, but this is rude and something like this is someone

  android:configChanges="orientation|screenSize" 

just do not want to use.

    1 answer 1

    When the device is flipped, an instance of the activity recreated, it is accordingly necessary to save the data and reinitialize it (if there were any).

    Use the methods: onSaveInstanceState or onRetainNonConfigurationInstance - they will help you save your data and restore it.

    But this is the case if you go to avoid data loss. To prohibit a change of orientation (which also relieves of this problem) there are other solutions.

    UPD. This page has even been translated into Russian: https://developer.android.com/guide/topics/resources/runtime-changes.html?hl=en

    UPD2. And this one too! https://developer.android.com/training/basics/activity-lifecycle/recreating.html