title: Android : Parent fragment of a nested fragment
body: <p>A <code>getParentFragment()</code> from my nested fragment is returning a <code>null</code>. I realise that getting a <code>null</code> means that the fragment is attached to the activity and not to the nested  container fragment. But I am explicitly nesting the child fragment inside the parent fragment using the child <code>FragmentManager</code> and thus think that I should not be getting a <code>null</code>. Could you tell me what I am missing? </p>
  
  <p><strong>Parent fragment</strong></p>
  
  <pre><code>public class UsageBreakUp extends Fragment implements Filter.OnFragmentInteractionListener {
  
    ....
  
    @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          getChildFragmentManager().beginTransaction().add(R.id.filter, new Filter()).commit();
      }
  
  ...
  
  }
  </code></pre>
  
  <p><strong>Child fragment</strong></p>
  
  <pre><code>public class Filter extends Fragment {
  
  ...
  
  
      public Filter() {
          if (getParentFragment() == null)
              Log.d(LOG_TAG, "parent fragment is null");
      }
  
  ...
  
  }
  </code></pre>