react-native-shared-group-preferences icon indicating copy to clipboard operation
react-native-shared-group-preferences copied to clipboard

Shared preferences do not work with multiple apps on Android and { useAndroidSharedPreferences: true }

Open SamuelBrucksch opened this issue 4 years ago • 1 comments

Hi,

from the description

You have multiple React-Native apps for iOS or Android and want them to be able to share data in a centralized location on the user's device.

The settings should be accessible from every app, right?

However on Android, when i use options { useAndroidSharedPreferences: true } that unfortunately does not work. I saw in your code, that you set MODE_PRIVATE for the shared preferences: https://github.com/KjellConnelly/react-native-shared-group-preferences/blob/0ff566921a47786a926721981f0bd61d7524d2d6/android/src/main/java/com/poppop/RNReactNativeSharedGroupPreferences/RNReactNativeSharedGroupPreferencesModule.java#L39

Unfortunately all other modes except private are deprecated now. But this results in not being able to get preferences in multiple apps. Even though its deprecated... as long as it still works would you consider to make the other modes configurable?

May i ask about the state of the content-provider implementation? I'm actually interested in that variant as well, as it would not be necessary anymore to use SharedPreferences.

BR Samuel

SamuelBrucksch avatar Feb 20 '21 22:02 SamuelBrucksch

Hi Samuel,

I believe android's SharedPreferences are poorly named, because it's data that isn't shared anywhere else except within a single app. So maybe at one point it wasn't, but now it is.

When I first created this module, I used public storage. A few months later, someone modified my code to use SharedPreferences instead. I'm not sure why exactly, but they wanted me to add an option for that. It worked for an extension or something like that if I remember correctly (or some sort of sub component of the parent app). And that is all they needed.

Anyways, my apps never used SharedPreferences, and I didn't write the code for it (other than accepting an option to use that instead of public storage). So I can't explain that part of the code since it was a pull request that I accepted without testing personally. I'm also not a very good Java programmer, nor Android, so I don't know much of the intricacies compared to RN or iOS.

As far as the content provider implementation, I started writing a bit of it. You can see I commented it all out in my last commit. I stopped because I figured out I could continue using this module as per the norm until this summer. So I'll probably start working on this again in... let me guess 2-4 months. In the meantime, if you want to figure it out yourself, I'd be quite happy with that :) I'm not even sure if this is the correct path, but it seems to have potential (again, I'm not very familiar with Android, so this might not even work).

KjellConnelly avatar Feb 20 '21 23:02 KjellConnelly