Activity object referenced null in onViewCreated?

189 views Asked by At

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?

1

There are 1 answers

0
laalto On
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;