We will start this section by providing an example of preferences editing:
The commit() method executes the operation immediately, while the apply() method executes it in the background.
Never obtain or manipulate your shared preferences from an application's main thread if you use the commit() method.
Make sure that all writing and reading is performed in the background. You can use AsyncTask for that purpose or, instead of commit(), use apply().
Get Mastering Android Development with Kotlin now with O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.