-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
[FEATURE REQUEST] Do not call onSharedPreferenceChanged() for self change #60
Comments
At this time, Harmony is meant to just be a re-implementation of You can use a |
Would you please explain how using HashSet can achieve what I want? If I add the information of who made the commit to the key value, wouldn't it be stored with that longer key? Or are you saying I would wait to receive it with the modified key, and then re-commit it without the extra info in the key? Maybe I'm completely missing what you are suggesting. |
I'm saying that if you make a call to something like |
Ah yes that's basically what I've done. The problem is if two or more writers are writing the same key at the same time, the listener won't know for sure which change notification was theirs and may discard the incorrect change. Am I right in predicting this? It shouldn't matter too much for me as it will still update the local value in memory from sharedPrefs with the second call. |
Regardless of when the key comes in, when you query the SharedPreferences, it'll give you the latest value stored. For example, if you call So even if you have some way to notify that your change came from the same Editor, all you'll be notified is that the key changed, not that the value changed. |
I'm in a situation where I do NOT want to be notified of a preference change that was just made from the same activity or service where the SharedPreferencesChangeListener is registered, but I DO want to be notified of changes made by a different class with a different instance of SharedPreferences.Editor(). One way to do this would be to pass a writer identifier tag with any commit call and then pass this to the SharedPreferencesChangeListener so all listeners know who made the change.
If this is already possible please let me know how! As it is now, I could keep track of which preference keys to ignore for the upcoming calls to onSharedPreferenceChanged() but that seems like a bit of an ugly solution, and I'd have to update this list every time I commit. Another way would be to unregister the listener before a commit and re-register right after. Also not ideal if it leads to missed changes from a different process.
P.S. Thank you for this library! I just spent all day migrating over to it. If this is not the place to ask for features, please let me know!
The text was updated successfully, but these errors were encountered: