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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -