Once you are moving from one activity to another activity the edited field will be available if you are navigate from the back stack not by the Intent.
example
Back Stack - >pressing the back button it will call the activity previous you are in.
Intent - > startActivity(new Intent(ActivityA.this,ActivityB.class));
If you use intent for changing the activity it will recreate the activity so the edited fields will not be available ..
so far if you are want to store the fields once user came back you need to use shared preferences..
Refer the official documentation
I can give you a sample to store the value in shared preference and retrieve from it.
public class CommonUtil {
public static void setUserName(String userName,Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("user_name",userName);
editor.apply();
}
public static String getUserName(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getString("user_name",null);
}}
To set values form activity
CommonUtil.setUserName("user",getApplicationContext());
CommonUtil.getUserName(getApplicationContext());
Once the user going to leave i will update the value from the textfields
Update the CommonUtil method..
where the key will be what the username,password
where the value will be taken from the textfields
public static void setValues(String key,String value, Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(key);
editor.putString(key,value);
editor.apply();
}
public static String getValues(String key,Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getString(key,null);
}
if you prefer looping that is also possible
final solution for your problem..
final EditText username,surname,middlename,dob,email,password;
Button get,save;
final String[] keyset = new String[]{"username","surname","middlename","dob","email","password"};
username = (EditText) findViewById(R.id.username);
surname = (EditText) findViewById(R.id.surname);
middlename = (EditText) findViewById(R.id.middlename);
dob = (EditText) findViewById(R.id.dob);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
final EditText[] editTexts = {username,surname,middlename,dob,email,password};
get = (Button) findViewById(R.id.get);
save = (Button) findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i =0 ; i<6 ;i++){
CommonUtil.setValues(keyset[i],editTexts[i].getText().toString(),getApplicationContext());
Log.d("got",editTexts[i].getText().toString());
}
}
});
get.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i =0 ; i<6 ;i++){
CommonUtil.getValues(keyset[i],getApplicationContext());
Log.d("got",CommonUtil.getValues(keyset[i],getApplicationContext()));
}
}
});