0

I am writing an PageViewer implementation using FragmentPagerAdapter.

Fragment child uses Activity reference in onViewCreated(..){} which is get from onAttach(Activity activity){}

private ScreenSlideActivity parentActivity = null; 

@Override   public void onAttach(Activity activity) {
    super.onAttach(activity);

    parentActivity = (SlideActivity) parentActivity; 
}

Now I am trying to use this parentActivity Object in onViewCreated() which is returning me null.

Any suggestion if I am missing anything while maintaining ViewPager behaviour?

laalto
  • 150,114
  • 66
  • 286
  • 303
CoDe
  • 11,056
  • 14
  • 90
  • 197

1 Answers1

2
parentActivity = (SlideActivity) parentActivity;

You're assigning a variable into itself which doesn't really change anything. A null will remain null.

You probably wanted:

parentActivity = (SlideActivity) activity;
laalto
  • 150,114
  • 66
  • 286
  • 303