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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -