0

I have a school planer app and I want to save the classes that are written in an EditText object. The problem is, the EditTexts are empty when I close the app and then open it again, and even when I press back. This may be a noob question, but I'm a beginner and I need help. Please answer quickly...

Anonymous
  • 315
  • 1
  • 5
  • 15
  • http://stackoverflow.com/questions/12074156/android-storing-retrieving-strings-with-shared-preferences – Shamas S Feb 13 '16 at 12:44
  • Sorry @ShamasS, that didn't help me – Anonymous Feb 13 '16 at 12:46
  • An Idea might be the following. You could use the following [Library](https://github.com/frankiesardo/icepick) which allow you to automatically store annotaded field and restore them. Therefore you would extract the value of the edit text in OnPause() and after OnResume() use them to set the text in the edit text. Keep in mind that the value must be extracted before you call the lib and at the other hand first let the lib restore the value before you use it. – Templum Feb 13 '16 at 12:46

1 Answers1

1

for saving edittext text you need to store the text into storage.

android support storage like

  1. Database
  2. Shared Preferences

For your problem you need to store your Edittext text into the storage when you change value.

And when you open it again you need to retrieve from the storage.

For you best option will be shared preferences. For more Go with This Example . This will make you understand save and retrieve shared preferences.

Short Example

Store Data

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
editor = pref.edit();
editor.putString("first_edittext", "value");
editor.commit();

Retrieve Data

SharedPreferences pref = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext());
pref.getString("first_edittext", "");
Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80