android - Fragment which implements Observer pattern -


i have maybe little bit stupid question, didn't find answers on this. have fragment , entity object extends observable. want fragment notified when changes made in entity, implemented observer there.

now have doubts observers have added , deleted. mean correct callbacks in fragment.

now i'm using onviewcreated add observer, ondestroyview delete observer, think there may better places it.

here sample code:

@override public void onviewcreated(view view, @nullable bundle savedinstancestate) {     super.onviewcreated(view, savedinstancestate);      wheelmanager.getinstance().addobserver(this);     preferencemanager.getinstance().addobserver(this); }  @override     public void ondestroyview() {         super.ondestroyview();         wheelmanager.getinstance().deleteobserver(this);         preferencemanager.getinstance().deleteobserver(this);     } 

i thankful answers.

upd: i've looked through official developer guide, find nothing question.

as you've said you're updating views, oncreateview , ondestroyview suitable places code.

there exception , that's when you're updating adapterviews , recyclerviews -- can instantiate adapter in onattach , start observing there (and stop in ondetach). can link adapter view in oncreateview , never worry npe's etc.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -