title: Is it necessary to check if parent activity is null in fragment onActivityCreated method?
body: <p>I'm reading the following <a href="http://neilgoodman.net/2012/03/12/working-with-fragments-on-android-part-2/" rel="nofollow noreferrer">tutorial</a> in which the author is showing how to implement a tab interface using fragments. Each of the fragments has a null check for the parent activity before setting a list adapter like this:</p>
  
  <pre><code>public class LocationListFragment extends ListFragment {
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          Activity activity = getActivity();
  
          if (activity != null) {            
             ListAdapter listAdapter = new LocationModelListAdapter(activity, FragmentTabTutorialApplication.sLocations);
             setListAdapter(listAdapter);
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to get a better understanding of the relationship between the activity and fragment lifecycles, so my question is: why is necessary to do this? The docs says that the <code>onActivityCreated</code> method is called after the <code>onCreate</code> method of the activity returns, if this is the case, how the activity can be null at this point?</p>