Mostly, there will be perference and profile in apps.

What is preference and profile?

1, What is preference?

Preference is the global setting (or config) of the app, such as the screen size or the volume:

2, What is profile?

Profile is the user setting (or data) in the app, after the user log in, the application will load the user’s favrite setting of the app, such as the theme or the user’s avatar. And it can also saves some data of the user such as user’s vip level or some messages:

How to read & write preference and profile in multi thread?

There will be a file related to the preference or the profile, and the data will be saved by json or another format. Consider the situation:

the solution

The principle of the solution is make the writing in one thread(UI thread), and reading in one thread(such as Sync thread).

If we need to do write on Sync thread, we can post it to UI thread, and wait the finished callback.

There will be a value in memory and the sync thread can read anytime. We should make sure the member can only be read or write in one thread.



评论需要翻墙 for disqus