When process reads the data from the SharedPreferences, it copies the values (data) and puts those data inside it's process inside the cache. It does this because reading/writing from disk is too slow. Generally, System creates cache process for Android Components. Now, your data from the SharedPreferences is stored in the component's cache process. Cache process has it's own memory space. Until the component is using the memory, it locks (critical section) in order to prevent other can't access that memory. The cache process should be killed so that other processes (or components) can now be able to access it. This is why when you relaunch you see the update.
Critical Section: https://en.wikipedia.org/wiki/Critical_section
Different Processes: https://developer.android.com/guide/components/activities/process-lifecycle.html
In thread-level, you use the keyword volatile
, so that you see the one thread updated data from second thread. But SharedPreferences can't be volatile because it is persistent storage.
That's why they explicitly stated SharedPreferences doesn't support on multiple processes