0

I am trying to find a callback for my FragmentActivity that happens 'after' all of the fragments have called 'onCreateView'.

The reason for this is that my Fragment implement my interface:

public interface LifeCycleFragment {
    public void onResumeFragment();
}

and when i call the fragment from MyActivity:

class MyActivity extends Activity
  onCreate() 
    fragment.onResumeFragment()

getActivity() ends up being null:

class MyFragment extends Fragment implements LifeCycleFragment

@Override
public void onResumeFragment() {
    Log.e(TAG, "- ON RESUME -");

    FragmentActivity activity = getActivity();
    // *****ACTIVITY IS NULL HERE AND THAT'S A PROBLEM ***//

I am not sure how to tackle this problem and any help would be appreciated.

Kamilski81
  • 14,409
  • 33
  • 108
  • 161

2 Answers2

1

Place getActivity() in override onActivityCreated method, and save it in the class for onResumeFragment(). I hope the Activity is still kept the same during onPause().

The Original Android
  • 6,147
  • 3
  • 26
  • 31
0

Would you like sample code to communicate between Fragment and Activity? I posted an answer in SO about it @ Passing data between fragments contained in an activity. The respective Google webpage is @ Communicating with Other Fragments.

Good luck and have fun...

Community
  • 1
  • 1
The Original Android
  • 6,147
  • 3
  • 26
  • 31