Search code examples
androidandroid-orientation

Information disappears when I rotate the phone


I wrote a programm,you must fill edittext and save it in the list view but when I rotate my phone the whole information is lost.What can I do not to lose my information?


Solution

  • The layout is reloaded on each screen rotation.

    You can bypass this by doing the following:

    Add this in the AndroidManifest.xml to the activity that should not be reloaded:

    <activity
        ...
        android:configChanges="keyboardHidden|orientation|screenSize"
        ...
    </activity>
    

    In the source code of the activity add the following method:

    public void onConfigurationChanged(Configuration newConfig) {
           super.onConfigurationChanged(newConfig);
    }
    

    Just leave the method blank, and when the screen rotates nothing will be reloaded.