Getting variable reference from fragment to activity

android, android-fragments, variables

Solution

Here is a good tuto :

Define an Interface then implement it in the activity

To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity. The Fragment captures the interface implementation during its onAttach() lifecycle method and can then call the Interface methods in order to communicate with the Activity.

Problem

I have an activity (MainActivity) that holds a Fragment (FragmentA) with an `ArrayList<Uri> array_list = new ArrayList<Uri>();`. How can my MainActivity get a reference of that array_list? Now if you ask me why'd I want to get a reference of a variable of a fragment to an activity that holds that fragment, I'd say, I'm planning to get the items in array_list when I click the action button on my MainActivity. I'm using ViewPager. I don't have fragment id's.

Original source