title: Viewbinding in Fragment causes KotlinNullPointerException running within lifecycle scoped coroutine
body: <p>I am setting up my Fragment like <a href="https://developer.android.com/topic/libraries/view-binding#fragments" rel="noreferrer">suggested in Google docs</a> as such:</p>
  <pre><code>    private var _binding: MyBinding? = null
      private val binding get() = _binding!!
  </code></pre>
  <pre><code>    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          _binding = MyBinding.inflate(inflater, container, false)
  </code></pre>
  <pre><code>    override fun onDestroyView() {
          super.onDestroyView()
          _binding = null
      }
  </code></pre>
  <p>Now I'm calling a coroutine that to my understanding should be scoped to the lifecycle of this fragment. It has a longer network call, then a success:</p>
  <pre><code>        lifecycleScope.launch(Dispatchers.Main) {
              when (myViewModel.loadFromNetwork(url)) {
                  true -&gt; responseSuccess()
                  false -&gt; responseFailure()
              }
          }
  </code></pre>
  <pre><code>    private suspend fun responseSuccess() {
          binding.stateSuccess.visibility = View.VISIBLE
          // ...
      }
  </code></pre>
  <p>Now when I press the Android system-back button while <code>loadFromNetwork</code> is still loading the fragment gets destroyed and <code>onDestroyView()</code> is called. As such <code>binding</code> now is <code>null</code>. I'm getting a <code>kotlin.KotlinNullPointerException</code>. What I not quite getting is why <code>responseSuccess()</code> is still being executed even though I thought that <code>lifecycleScope</code> is specifically meant for these kind of situations. According to <a href="https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescope" rel="noreferrer">Google Docs</a>:</p>
  <blockquote>
  <p>A LifecycleScope is defined for each Lifecycle object. Any coroutine launched in this scope is canceled when the Lifecycle is destroyed.</p>
  </blockquote>
  <p>I understand this code can be fixed by a few changes and some manual null-checks, but I would like to understand how to fix this without boilerplate and in the intended manner. What is the purpose of using lifecycleScope to be lifecycle aware if not exactly this?</p>