Mar 24, 2017

Android: Shared Preference: apply() vs commit()


  • apply() was added in 2.3, it commits without returning a boolean indicating success or failure. apply() schedules the data to be written asynchronously. It does not inform you about the success of the operation.
  • commit() returns true if the save works, false otherwise. commit() writes the data synchronously (blocking the thread its called from). It then informs you about the success of the operation.
  • apply() was added as the Android dev team noticed that almost no one took notice of the return value, so apply is faster as it is asynchronous.

No comments:

Post a Comment