Difference Between commit and apply in Android SharedPreferences
<p>SharedPreferences are used to save Application data in Android.</p>

<p><code>commit()</code> and <code>apply()</code> both are used to save the changes in the shared preferences.</p>

<p>As mentioned in Android Library:</p>

<pre><code>public abstarct void apply():
</code></pre>

<blockquote>
  <p>Unlike commit(), which writes its preferences out to persistent
  storage synchronously, apply() commits its changes to the in-memory
  SharedPreferences immediately but starts an asynchronous commit to
  disk and you won't be notified of any failures. If another editor on
  this SharedPreferences does a regular commit() while a apply() is
  still outstanding, the commit() will block until all async commits are
  completed as well as the commit itself.</p>
</blockquote>

<pre><code>public abstract boolean commit ():
</code></pre>

<blockquote>
  <p>Commit your preferences changes back from this Editor to the
  SharedPreferences object it is editing. This atomically performs the
  requested modifications, replacing whatever is currently in the
  SharedPreferences.</p>
</blockquote>

<p>Does this mean that the changes made by <code>commit()</code> are instant as compared with <code>apply()</code>? Which one is better?</p>

<p>If I need to use the same shared preference value in the next immediate activity, which one should I use? As I have seen if the value of Preference is updated it is not reflected till the application is restarted.</p>
