We have and Android App that contains two Activities MainActivity and PageTwo. In the MainActivity we have an EditText widget set to accept number input only and a Button that goes to the next activity with the aid of an Intent. On the second activity PageTwo we have a Button that returns the user to the MainActivity with an Intent. When we enter a value in the EditText field and make the trip from the MainActivity to PageTwo activity and back the value is seemingly erased unless you use the device (emulator) back button. I am trying to maintain the Activity State of this one EditText variable
code snippets
EditText ETage;
int vAGE;
static final String V_AGE = "vAGE"; //KeyValue Pair
@Override
public void onSaveInstanceState(Bundle outState){
outState.putInt(V_AGE,vAGE);
super.onSaveInstanceState(outState);
}
//@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
vAGE = savedInstanceState.getInt(V_AGE);
ETage.setText(String.valueOf(vAGE));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//if(savedInstanceState != null){
//vAGE = savedInstanceState.getChar(V_AGE);
//}
setContentView(R.layout.activity_main);
ETage = (EditText)findViewById(R.id.editTextAge);
From what I understand from your question you can do like this in second page: