title: How does a fragment attach itself to an activity?
body: <p>How exactly does a fragment attach itself to an activity when all I did was the follow code.</p>
  
  <pre><code>    public class FragmentA extends Fragment{
         @Override
         public View onCreateView(Layout inflater,ViewGroup container, Bundle  savedInstanceState){
            return inflater.inflate(R.layout.fragment_b, container, false);
         }
         @Override
         public void onActivityCreated(Bundle savedInstanceState){
             Button test = (Button) getActivity().findViewById(R.id.fragBtn1);
         }
  
       }
  </code></pre>
  
  <p>I am confused about the code above because I am not so sure how does the fragment gets binded to an activity when all I declared was the code above and added the fragment into the main_activity.XMl layout file.</p>
  
  <p>So my only assumption for this is that the XML layout has a reference to the main activity because it is called by setContentView() in the activity. As a result of this reference the XMl file is able to pass on the context of the activity to the fragment down to the fragment and therefore allowing the fragment to bind onto the activity.</p>
  
  <p>Am I correct in this assumption?</p>