I’m new to android (and java) and I am wondering what’s the mechanism to communicate between objects? Like if I want to monitor a private member’s value, if it changes, I want a method to be triggered.
I know for UI event there’s event listener. But what if it’s not a mouse click, but a private member’s value changing? I tried intent/broadcastreceiver, but i don’t think that’s for what I want to do..
Thank you so much!!
You can use publisher subscriber based approach here. Your class which contains the private (
Publisher) member will have a methodRegisterForChangethat method you will take some interfaceISomeInterfaceas a parameter and theSubscriber class would have implemented that interface. Once there is a change in private member you can callSomeMethodmethod of that interface to notify theSubscriberthat my private member has been changed