Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

Read following answer

Restore values on screen rotation

Solution 2:

On screen orientation change Activity getting restarted so if you are not saving state of it then it can destroy due to error like null pointer exception and sometime android not shows any log of forceclose for saving state of your activity take a look at this : Configuration Changes

Solution 3:

When you change the orientation of the device the app is being destroyed and then restarted. For you app to remember where the user was, plus other things, you need to implement code in your onCreate to read the saved state and also you need to save the state before the app is closed, this can be done in a number of places and where depends on your needs but could be onPause(), onDestroy or

@OverrideprotectedvoidonSaveInstanceState( Bundle outState )
{
            // save your sate heresuper.onSaveInstanceState( outState );
}

protectedvoidonCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );

    setContentView( R.layout.layout_main );

    // if there is a saved state restore itif( savedInstanceState != null )
    {
    }
    else
    {

    }
}

Post a Comment for "App Shows Main Screen After Screen Rotation"