1. Check out our companion app, Forums for Android! Download from Google Play

Testing savedInstanceState

Discussion in 'Application Development' started by andywhoa, Jul 20, 2010.

  1. andywhoa

    andywhoa Well-Known Member
    Thread Starter

    May 15, 2010
    Software Engineer
    West Des Moines, IA

    I would like to test my app and make sure my instance state handling is working properly.

    To do this, I've ran my app in the emulator, simulated a phone call, answered, hung up and been brought back to my application.

    I've overridden the onSaveInstanceState method:
    Code (Text):
    1.     @Override
    2.     protected void onSaveInstanceState(Bundle outState) {
    3.         super.onSaveInstanceState(outState);
    4.         // save screen state
    5.         outState.putString(LOGIN_USER_NAME, mUsernameTextbox.getText().toString());
    6.         outState.putString(LOGIN_USER_PASS, mPasswordTextbox.getText().toString());
    7.     }
    I have NOT overridden the onRestoreInstanceState method.

    When I begin my test, the onSaveInstanceState method is invoked and my Bundle is written to. However, when I hang up the phone, it appears that my original Activity is brought back. As I said, I have NOT overridden the onRestoreInstanceState method. I've no code to restore the instance. Yet, everything on the screen is the way I left it. The EditTexts are populated, the AlertDialog that got thrown up while the phone was up was showing, everything was there. How is this possible and how can I do a real test?

    Thanks for your help


Share This Page