title: What is the difference between requireActivity and onActivityCreated
body: <p>In my code I was inconveniently loading pictures after <code>onCreateView()</code> because I was not sure if the activity was available yet. Because Glide required an activity context I placed the section of code into <code>onActivityCreated()</code>:</p>
  <pre class="lang-kotlin prettyprint-override"><code>override fun onActivityCreated(savedInstanceState: Bundle?) {
      super.onActivityCreated(savedInstanceState)
  
      //Crash unexpected since onActivityCreated should always have activity available
      Glide.with(activity!!)
          .load(viewModel.moment!!.mediaPath)
          .into(binding.momentPhoto);
  }
  </code></pre>
  <p>However, after looking through some best practices on Github many examples load the photos in <code>onCreateView()</code>. They do this by using the <code>requireActivity()</code> method:</p>
  <pre class="lang-kotlin prettyprint-override"><code>override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      binding = DataBindingUtil.inflate(layoutInflater, R.layout.fragment_photo_editor, container, false)
  
      Glide.with(requireActivity())
            .load(viewModel.moment!!.mediaPath)
            .into(binding.momentPhoto);
  
      return binding.root
  }
  </code></pre>
  <p>Does anyone know what the difference between using an activity reference after <code>onActivityCreated()</code> and getting the activity reference from <code>requireActivity()</code>?</p>