Skip to content Skip to sidebar Skip to footer

Communication Between Fragment And Other Activity

public class FragActivity1 extends Fragment implements View.OnClickListener { View view; ImageButton name_change__btn, status_change_btn, profile_change_btn; ImageView

Solution 1:

Communication between fragments and the activity they are attached to is explained here. From the fragment to the activity you simply use getActivity for a reference to the activity. From the activity to the fragment you can use the findFragmentById(R.id.fragment_id) method of the FragmentManager for a reference to the fragment you want to communicate with.

Communication between activities is realized through Intent s and their Extras as described here. You basically put your Data in a Bundle and insert it in the Ìntent with putExtras().

In your case you should first have the fragment communicate with its activity and then start a new activity with a Bundle from here.


Solution 2:

You should use LocalBroadcastManager To commuicate between two Activities The concept is simple and can be implemented easily check below link

https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiT89LA4rbOAhXLso8KHexGAkwQFggdMAA&url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fsupport%2Fv4%2Fcontent%2FLocalBroadcastManager.html&usg=AFQjCNGameWXe05OE9ufTkz6rzSydOw91g


Post a Comment for "Communication Between Fragment And Other Activity"