title: SharedPreferences and Thread Safety
body: <p>Looking at the <a href="http://developer.android.com/reference/android/content/SharedPreferences.html">SharedPreferences docs</a> it says: </p>
  
  <blockquote>
    <p>"Note: currently this class does not
    support use across multiple processes.
    This will be added later."</p>
  </blockquote>
  
  <p>So in and of itself it doesn't appear to be Thread Safe. However, what kind of guarantees are made in regards to commit() and apply()?</p>
  
  <p>For example:</p>
  
  <pre><code>synchronized(uniqueIdLock){
     uniqueId = sharedPreferences.getInt("UNIQUE_INCREMENTING_ID", 0);
     uniqueId++;
     sharedPreferences.edit().putInt("UNIQUE_INCREMENTING_ID", uniqueId).commit();
  }
  </code></pre>
  
  <p>Would it be guaranteed that the uniqueId was always unique in this case?</p>
  
  <p>If not, is there a better way to keep track of a unique id for an application that persists?</p>