Possible Duplicate:
How do I save an Android application's state?
I'm currently working an application that has the following behavior : i am using 2 Edittext and there are some value which i type in it and when i press the button it will move on to the next page or activity ,But the problem is here when i return back to activity i dont find the values 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("");
}
}
You must override the onSaveInstanceState(Bundle b) to save your data before loading the new activity.
Also you must restore overriding the onRestoreInstanceState and getting the values back...
you can se more information here:
Saving Android Activity state using Save Instance State
or
http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With