I am new to Android Fragment and trying to find out the Fragment to Activity interface. What is the best approach (best practice) in Android for sharing activity fragmentation?
Let's say I have FragmentA and ActivityA. After the FragmentA popup appears on the screen, I would like to execute somemethod (possibly related to the UI) in ActivityA
Two (template) Solutions are possible here :
- In FragmentA getActivity and turn on Activity in ActivityA, and then call somemethod.
- In FragmentA, create an interface callback, and then implement this callback in ActivityA. Then in the callback, call somemethod.
Which template is more common / perfer in Android development and why. Or do you have an even better way of communicating from fragment to activity on Android to share with me?
Any comments, opinions and suggestions are welcome and welcome. ^^.
source share