Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SamuelBrucksch opened this issue Feb 20, 2021 · 1 comment

Comments

@SamuelBrucksch
Copy link

SamuelBrucksch commented Feb 20, 2021

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:

return reactContext.getApplicationContext().getSharedPreferences(appGroup, Context.MODE_PRIVATE);

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

@KjellConnelly
Copy link
Owner

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants