-1

I am making a Sample of twitter integration ,i am fetching user information on click of button. Data is coming on screen it is working fine with portrait modeb but as i changed to landscape mode ,data loss.

how to solve this issue, i dont know how to use onSavedInstance method to solve this problem. please help

Uzeeta Siloth
  • 45
  • 1
  • 2
  • 6

1 Answers1

1

You need to override android default methods like onSaveInstanceState and onRestoreInstanceState check this example.

 @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save the user's current game state
        savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
        savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);

        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // Always call the superclass first

        // Check whether we're recreating a previously destroyed instance
        if (savedInstanceState != null) {
            // Restore value of members from saved state
            mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
            mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
        } else {
            // Probably initialize members with default values for a new instance
        }
        ...
    }

   //you can retrieve saved values from here 
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can restore the view hierarchy
        super.onRestoreInstanceState(savedInstanceState);

        // Restore state members from saved instance
        mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
        mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
    }

click here to find more about this

gkondati
  • 516
  • 4
  • 16