How to organize data transfer from a fragment to an Activity? read ( https://developer.android.com/guide/components/fragments.html ) that for this you need to make an interface in the fragment class and then implement it in the Activity then in the fragment when called in the onAttach () method whose input goes to the Activity to which the fragment is attached. This Activity needs to be converted to an interface type. But I decided to try to transfer data from the Fragment class to the Activity class via the Intnent intent.putExtra () this scheme works, then why the interface, what does it provide?

what is interesting is onAttach (Activity a) - This method was deprecated in API level 23.Use onAttach (Context) instead

public static class FragmentA extends ListFragment { ... // Container Activity must implement this interface public interface OnArticleSelectedListener { public void onArticleSelected(Uri articleUri); } ... } 
  • one
    Callback methods are used when action is required in one class on an event in another class. For communications in the application, use the EventBus library and do not bother yourself - pavlofff

0