Changed Notification raised even when the value is the same
See original GitHub issueI have a RealmObject with a private property with get / set accesor.
public class Dog extends RealmObject
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
(Nothing fancy there). I have a subscritor to a list of dogs:
RealmResults<Dog> mydogs = realm.where(Dog.class).findAll();
mydogs.addChangeListener((dogs, changeSet) -> //any update stuff);
As expected, anytime the name of any dog is changed the listener is hit, however what I didn’t expect is that the listener is hit everytime I assign a name to the name field even if it is the same as it has, I don’t know if this behavior is by design, so I had to add something like this:
public void setName(String name)
{
if (!this.name.equals(name)
this.name = name;
}
I know that this is an easy solution, but I wonder why the listener is launched even if the underlined data is not changed. Is this the expected behavior? (I’m using Realm 4.1.0 on a 6.0 Android emulated device)
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (9 by maintainers)
Top Results From Across the Web
How to: Implement Property Change Notification - WPF .NET ...
Enable your properties to automatically notify a binding source when the property value changes in Windows Presentation Foundation (WPF).
Read more >c# - How to trigger event when a variable's value is changed?
This allows you to run some code any time the property value changes. You could raise an event here, if you wanted.
Read more >Notifications - System experiences - Human Interface Guidelines
A notification gives people timely, high-value information they can understand at a glance.
Read more >Customize Support Settings - Salesforce Help
Support settings can help you automate case management. Choose email templates, default case owner, case notifications, and more.
Read more >If You're Going to Raise Prices, Tell Customers Why
Many companies, and even entire industries, routinely raise ... Call the action a price increase, not a price adjustment, a price change, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

+1 for a way to get notified of actual changes of the model. The update functionality is great because it saves a lot of code that is boilerplate, but if there is no way of knowing whether it modified the model, we can not use it to update views. In our case we query our server every second for a JSON of the model. I would love to just refresh the view in the on change notification but it will trigger every second regardless of changes to the JSON from the server.
See https://github.com/realm/realm-core/issues/2787 for a discussion of this on Realm Core level.
So this means that you get notification because a
setoperation is logged by Core which is indeed a requirement not to miss changes in a synchronized setting.Which is why only the user knows if “not setting the value” is not necessary.