Saving Several Edittext After Program Closes
I'm trying to make a Character sheet for a DnD like game. The point is to take user input and store it for future viewing and changing. Maybe I'm looking for a solution that doesn'
Solution 1:
Here is one example:
publicclassCharacter_activityextendsAppCompatActivity {
privateEditText playerEditText;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_character_redo);
playerEditText = (EditText) findViewById(R.id.player);
}
@OverrideprotectedvoidonRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
playerEditText.setText(savedInstanceState.getString("SavedPlayer", "");
}
@OverrideprotectedvoidonSaveInstanceState(Bundle outState) {
outState.putString("SavedPlayer", playerEditText.getText().toString());
super.onSaveInstanceState(outState);
}
}
This will save your text over an orientation change. If you want to save it when your process is killed then you need to look at SharedPreferences
instead of a Bundle
.
http://developer.android.com/training/basics/data-storage/shared-preferences.html
Post a Comment for "Saving Several Edittext After Program Closes"