title: Android: Update SharedPreferences
body: <p>I'm trying to keep a counter of the times my application is lauched. To do that, I need to keep information stored in the device, even once the application has been killed.</p>
  
  <p>I read this link:</p>
  
  <p><a href="http://developer.android.com/guide/topics/data/data-storage.html#pref" rel="nofollow">http://developer.android.com/guide/topics/data/data-storage.html#pref</a></p>
  
  <p>And I thought the easiest way to implement this, would be using SharedPreferences. So I wrote this code:</p>
  
  <pre><code>final String PREFS_NAME = "MyPrefsFile";
  
  
  SharedPreferences settings = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
  int TimesLaunched = settings.getInt("TimesLaunched", 0);
  
  TimesLaunched++;
  
  SharedPreferences.Editor editor = settings.edit();
  editor.putInt("TimesLaunched", TimesLaunched);
  
  
  editor.commit();
  </code></pre>
  
  <p>I found out it works the first time, so it chages from 0 to 1, but that is all. The following times I launched the app nothing happened. </p>
  
  <p>Does anyone know what is wrong?</p>