Shared preferences between two processes of the same application

Solution 1:

In Android < 2.3 it works. One process can write changes and the other process can read the changes. The code to read/write shared preferences files (they are actually stored in files) checks if there have been any changes made to the file before reading/writing and they update their cached version accordingly.

In Android > 2.3 it works, but you need to specifically set MODE_MULTI_PROCESS when calling getSharedPreferences().

In Android 2.3 it is broken and it doesn't work :-(

Please note that MODE_MULTI_PROCESS is deprecated in API Level 23 (Android M).

Solution 2:

You can check out https://github.com/hamsterksu/MultiprocessPreferences library which provides SharedPreferences-like APIs for accessing SharedPreferences data via a ContentProvider. It also looks like a good alternate after Google removed MODE_MULTI_PROCESS from Android 6.