Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:30:05+00:00 2026-06-01T01:30:05+00:00

I am having a simple code where i want to know when does onRestoreInstanceState

  • 0

I am having a simple code where i want to know when does onRestoreInstanceState get called during program execution in android?

Please help me out.

Thanks in advance.

My first Activity is as follows

public class AbcActivity extends Activity {
Button b1;
EditText ed1;
Bundle b = new Bundle();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.v("Tag", "inside oncreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    b1 = (Button) findViewById(R.id.button1);
    ed1 = (EditText) findViewById(R.id.editText1);

    b1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(),
                    SecondActivity.class);
            startActivity(intent);
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    Log.v("Tag", "inside onsave instance state");

    outState.putString("key", ed1.getText().toString());
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    Log.v("Tag", "inside on restore instance state");
    super.onRestoreInstanceState(savedInstanceState);

    if (savedInstanceState != null) {
        Log.v("tag", "inside if");
        String str = savedInstanceState.getString("key");
        ed1.setText("" + str);
    }

}

}

my second activity code is as follows

public class SecondActivity extends Activity {
Button back;

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v("Tag", "inside 2 oncreate");
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);

    back = (Button) findViewById(R.id.button1);

    back.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(),
                    AbcActivity.class);
            startActivity(intent);
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    Log.v("Tag", "inside 2 onsave instance state");
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    Log.v("Tag", "inside 2 on restore instance state");
    super.onRestoreInstanceState(savedInstanceState);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:30:06+00:00Added an answer on June 1, 2026 at 1:30 am

    As the documentation states:

    This method is called after onStart() when the activity is being re-initialized from a previously saved state
    …
    This method is called between onStart() and onPostCreate(Bundle)

    This is the case when your Activity is re-created after being killed by the system or after a configuration change, and it saved its state in onSaveInstanceState(Bundle) – which is always called before an Activity is killed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to know, the best methodology (with code sample please) of having a
I really need help on this one. I am having a simple login form
Does anybody know, in a .tt file, where code.VsNamespaceSuggestion() gets its namespace from? I'm
Ok, I know I must be missing something simple. Thank-you for your help! [EDITED
Does anyone know where I can find some example code for implementing ajax tabs
What are the options for having a simple blog, content management system that will
by simple I mean, having buttons: bold, italic, numbered list bullet point list indent
Having some trouble with what should be a very simple scenario. For example purposes,
Instead of having to remember to initialize a simple 'C' structure, I might derive
I'm stuck in having to write a simple spam filter I'm not really sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.