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

  • Home
  • SEARCH
  • 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 6882049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:12:19+00:00 2026-05-27T05:12:19+00:00

I have two activities A, B . Now from A i call B by

  • 0

I have two activities A, B . Now from A i call B by pressing a button (using startActivity()) , then press Back key to go back to A . Now when i press Button again to go to B , fresh activity is called (as expected).

Now can someone tell me how to show old previous state of B ?

I have read this article
Saving Android Activity state using Save Instance State , but couldn’t help myself 🙁

public class B extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);

    if(savedInstanceState!=null){
        EditText editText=(EditText)findViewById(R.id.editText1);
        editText.setText(savedInstanceState.getString("EditBox"));
    }
}

@Override
protected void onSaveInstanceState(Bundle onSaveInstanceState) {
    System.out.println("B.onSaveInstanceState()");
    super.onSaveInstanceState(onSaveInstanceState);
    onSaveInstanceState.putString("EditBox","Hello");
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    System.out.println("B.onRestoreInstanceState()");
    super.onRestoreInstanceState(savedInstanceState);
    EditText editText=(EditText)findViewById(R.id.editText1);
    editText.setText(savedInstanceState.getString("EditBox"));
}}

My Class A

public class A extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button=(Button)findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
             Intent i=new Intent(StartActivityforresultActivity.this,B.class);
             startActivity(i);
        }
    });


}
  • 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-05-27T05:12:20+00:00Added an answer on May 27, 2026 at 5:12 am

    With what it sounds like you’re trying to do you have two options:
    1. Save the state of B when B’s onDestroy or onBackPressed is called. You’ll have to save this to memory or write it out using some sort of persistence (SharedPreferences, local file, etc). Then whenever B is started, check to see if that data exists and use it to load the state.
    2. Override onBackPressed so that when it is pressed you aren’t calling super.onBackPressed. Instead start an instance of activity A and set your intent’s flags to be FLAG_ACTIVITY_REORDER_TO_FRONT before calling startActivity. So something like this:

        Intent intent = new Intent(this, A.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
    

    Now when you hit back, it should find the instance of A that is in your activity stack and just bring it to the front. You may have to add the same flag whenever you start B as well.

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

Sidebar

Related Questions

I have an application which has two Activities, let's call them A and B.
I have two activities A and B. Activity A starts activity B. Now I'm
I have two activities A and B, and from activity A, I click on
I want to know that if I have two activities in a program then
I have a Tab Interface with two separate activities, lets call them ActA and
I have two activities: one displays an image and a button, the other displays
Right now I have two activities. My goal is to allow the user to
I have two classes(activites) in android: ProfileScreen. FillDetailScreen. Now from activity 1 I am
I have two Sharepoint lists: - Assignments - Activities The activities list has a
I have two applications written in Java that communicate with each other using XML

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.