Saving activity on Android When switching to another activity

Possible duplicate:
How to save Android application state?

I am currently working on an application that has the following behavior: I use 2 Edittext, and there is some value that I enter into it, and when I click the button it will go to the next page or activity. But the problem is here, when I return to activity, I do not find the value in edittext PLease, help me .. Please let me know the code ... Thanks in Advance ....

This is my code ....

public class TestsampleActivity extends Activity { Button b1,b2; TextView t1; EditText e1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); b1= (Button)findViewById(R.id.btn1); b2= (Button)findViewById(R.id.btn2); t1=(TextView)findViewById(R.id.tv1); e1=(EditText)findViewById(R.id.et1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ add(); } }); b2.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ del(); } }); } public void add() { String s1= e1.getText().toString(); Intent intent=new Intent(this,next.class); intent.putExtra("name",s1); startActivity(intent); /* String s1= e1.getText().toString(); //t1.append(s1); t1.setText(s1); */ } public void del() { e1.setText(""); t1.setText(""); } } 
+4
source share
3 answers

You must override onSaveInstanceState (Bundle b) to save your data before loading a new action.

You should also restore the onRestoreInstanceState override and return the values ​​...

You can find more information here:

Saving Android Activity State Using Instance Saving State

or

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState (android.os.Bundle)

+1
source

Save the text in editing until the package is provided in the onSaveInsanceState () method . Then in onRestoreInstanceState (), use the values ​​you saved to restore the text in EditTexts.

+1
source

When returning to the previous step: Use the following method:

 Intent intent_obj=new Intent(); String id = intent_obj.getStringExtra("id"); e1.setText(id); 

It will work .... !!!

+1
source

All Articles