Fragment Callbacks vs EventBus in Android -


i have faced problem. activity fragment container, communicate between activity , fragments used common callback approach. in case activity has implement tons of callback interfaces depending on fragment count.
don't hardcode , unreadable code. in case class declaration can take several lines list interfaces.
trying rid of this.

there approach use eventbus pattern.
in activity

eventbus.getdefault().register(this); 

in fragment

eventbus.getdetault().post(new myevent(description)); 

and handle several event types in activity.

maybe there better use eventbus here instead default callback approach ??
or maybe there fault activity holding lot of fragments (god object) , better use activities instead fragment ?

please suggest approach better ?

for simple 1 activity 1 fragment hierarchy, callback simplest decision go. think activity containing fragment, , fragment contains swipe-able viewpager, , each tab of viewpager has fragments a,b,c.

the fragment a,b,c go long journey send event mother activity, , can lost interface connectivity between activity , children when restored during crazy complex android activity-fragment lifecycle dances. in case, eventbus otto can choice.

the drawback of event bus approach is, hard maintain event come from. so, keeping few sender recommended.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -