title: Android Save SharedPreferences from EditText
body: <p>In my application, I have an <code>EditText</code> for the user to enter a text. So, I want to save the text of an <code>EditText</code> in <code>SharedPreferences</code>. I want the <code>SharedPreferences</code> to be updated when the text from editText is changed.     </p>
  
  <blockquote>
    <p>I am using this code:</p>
  </blockquote>
  
  <pre><code>message = (EditText) findViewById(R.id.et_message);
  
  final SharedPreferences prefs = PreferenceManager
      .getDefaultSharedPreferences(this);
  
  message.addTextChangedListener(new TextWatcher() {
  
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count){
            prefs.edit().putString("autoSave", s.toString()).commit();
      }
  
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after){
  
      }
  
      @Override
      public void afterTextChanged(Editable s){
  
      }
  });
  </code></pre>
  
  <ol>
  <li>I am not sure, whether to put <code>prefs.edit().putString("autoSave",
  s.toString()).commit();</code> in <code>onTextChanged()</code> or in afterTextChanged.</li>
  <li>I tried to put it in both <code>onTextChanged()</code>  and afterTextChanged but when I restart the application, there is no text that I edited. </li>
  </ol>