Data Sharing between Fragments and Activity in Android

Many ways :

1) Activity -> Fragment

2) Activity -> Fragment

3) Fragment -> Activity

  • In your Fragment : create un interface with getter and setter methods (callback methods)
  • In your Activity : implement the interface

4) Fragment -> Activity

  • In your Activity : Create public getter and setter or other methods
  • In your Fragment : called public activity getter, setter or other methods using :

    getActivity().getSomething(), getActivity().setSomething(args) or getActivity().someMethod(args)

Leave a Comment