Search code examples
androidandroid-orientation

App shows main screen after screen rotation


I have been working on an andoid app since a few days. I have two layouts in my MainActivity, first one shows SearchBox and second shows the Results. When the app shows the results and the app orientation is changed, the app get back to the first screen. I may not be clear with my engish but see these simple steps :

 Open App -> 1st screen(MainActivity) -> 2nd Screen(MainActivity) -> Now If I rotate the screen It goes back to 1st screen.

I searched on internet about it, but I was unable to find anything on it. Any help would be Appreciated to solve this.


Solution

  • You should use onSaveInstanceState to save your state, and then recreate it in onCreate.

    Read following answer

    Restore values on screen rotation