1

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

  <activity
        android:name=".UnityActivity"
        android:process=":UnityKillsMe"/>

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 process=":UnityKillsMe", 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 process=":UnityKillsMe", the edits will be overwritten, and are lost.

How do I refresh SharedPreferences in the main process ?

Community
  • 1
  • 1
Emanuel Graf
  • 756
  • 17
  • 37
  • 1
    another process? unity is completely single-threaded. you should not use or be involved in other processes at the Android level in any way whatsoever. there is no conceivable reason you would need to do any such thing to make a simple video game. Perhaps you should **state what you are trying to do?** – Fattie Jun 12 '16 at 15:18
  • thanks @JoeBlow for helping. this question is more about java than unity, I launch my untiyactivity(my inapp videogame) from my Java application on android. But I fixed it with the answer below. – Emanuel Graf Jun 12 '16 at 15:22
  • 1
    Dear Emanuel. Fair enough, I get what you mean. It is a huge PITA to treat unity projects as separate activities on Android. I hope, it does not cause you too much trouble! – Fattie Jun 12 '16 at 15:26

1 Answers1

1

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.

Community
  • 1
  • 1
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63