Emanuel Graf Emanuel Graf - 8 months ago 42
Java Question

sharedPreferences wont update if edited in another process

I have an unity activity, which launches in another process than my App:


I save my sharedPreferences encrypted with this question(just in case this affects my problem and I have no idea)
now if I want to edit a sharedPreference in
, the edits are not beeing accessable in mainProcess, it just takes the old version of the sharedPreferences. Not until I kill the mainProcess and launch the app again. If I do not kill the mainProcess, and edit the sharedPreferences, while they have been edited in
, the edits will be overwritten, and are lost. how do I refresh sharedPreferences in the main process ?


The current implementation of SharedPreferences in Android is not process-safe.

From the docs:

Note: currently this class does not support use across multiple processes. This will be added later.

The question is do you really need multiple processes in your application?

If you really do, i would suggest you to take a look at Tray, or consider some other form of persistent storage, such as a database.

Check out this answer also.