简体   繁体   中英

How to save state of activity while starting other activity through StartActivity() method od Intent?

I have an ActivityA , which starts ActivityB through Intent's startActivity() method.The context is as below:

A.java

String name = edittext.getString();  
Intent i = new Intent(A.this,B.class);  
Bundle b = new Bundle();  
b.putString("Name",name);  
i.putExtras(b);  
startActivity(b);  

B.java

Bundle bb=getIntent().getExtras();
String namee=bb.getString("name");

In this B Activity there will be Back button which when clicked takes control back to A as below:

     back.setOnClickListener(new OnClickListener()
    { 
        public void onClick(View arg0) {
   Intent backToDetails = new Intent(B.this,A.class);
   startActivity(backToDetails);
}
     });


Now control comes to ActivityA . When I again start Activity B from Activity A , the previous value of the name is lost .So, I again get new Value by overwrting old value in Activity B . So, how to save previous name value ? How to save the state of Activity B? Can any one help me in sorting out this issue?

Thanks In Advance,

You just have to save the state of your activity B. In this related question there is a complete answer to solve your problem. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM