Skip to content

Instantly share code, notes, and snippets.

@codingpizza
Created April 2, 2018 18:49
Show Gist options
  • Save codingpizza/6976ae80a82b0cfa006a4a3734c494b9 to your computer and use it in GitHub Desktop.
Save codingpizza/6976ae80a82b0cfa006a4a3734c494b9 to your computer and use it in GitHub Desktop.
MainActivity
public class MainActivity extends AppCompatActivity {
private EditText et_name,et_surname,et_email;
private static final String KEY_NAME = "NOMBRE";
private static final String KEY_SURNAME = "NOMBRE";
private static final String KEY_EMAIL = "NOMBRE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_name = findViewById(R.id.et_name);
et_surname = findViewById(R.id.et_surname);
et_email = findViewById(R.id.et_email);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
if (outState != null) {
outState.putString(KEY_NAME,et_name.getText().toString());
outState.putString(KEY_SURNAME,et_surname.getText().toString());
outState.putString(KEY_EMAIL,et_email.getText().toString());
}
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null ){
if (savedInstanceState.containsKey(KEY_NAME) || savedInstanceState.containsKey(KEY_SURNAME) || savedInstanceState.containsKey(KEY_EMAIL)) {
et_name.setText(savedInstanceState.getString(KEY_NAME));
et_surname.setText(savedInstanceState.getString(KEY_SURNAME));
et_email.setText(savedInstanceState.getString(KEY_EMAIL));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment