Android send Data from fragment to Activity -


i'm working on android app, datas in fragment , want use them in other fragment. looking create bundle, in activity simple getbasicinfos() method return bundle send other fragment. problem can't use method in activity.

fragment = new dashboardfragment();             fragment.getbasicinfos(); //does not recognize method             toolbar.settitle(getresources().getstring(r.string.dashboard));             break; 

i want know if there better way, or more simple.

create interface in fragment , implement interface in activity while instantiating fragment = new dashboardfragment(this); pass listener , in fragment constructor save this

public dashboardfragment(fragmentlistener listener) {     this.listener = listener; } 

and use listener pass data activity.

hope helps.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -