title: viewModelScope not cancelled
body: <p>After watching <a href="https://youtu.be/BOHK_w09pVA?t=1425" rel="noreferrer">Sean's explanation on Android (Google I/O'19)</a> I've tried the same:</p>
  
  <pre><code>init{
      viewModelScope.launch {
          Timber.i("coroutine awake")
          while (true){
              delay(2_000)
              Timber.i("another round trip")
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately <code>onCleared</code> it's called when the activity is killed but not when it's put in background ("when we move away from the Activity...", background is "moving away" imho ^^).<br>
  And I get the following output:</p>
  
  <pre><code>&gt; ---- Activity in Foreground
  &gt; 12:41:10.195  TEST: coroutine awake
  &gt; 12:41:12.215  TEST: another round trip
  &gt; 12:41:14.231  TEST: another round trip
  &gt; 12:41:16.245  TEST: another round trip
  &gt; 12:41:18.259  TEST: another round trip
  &gt; 12:41:20.270  TEST: another round trip
  &gt; ----- Activity in Background (on onCleared not fired)
  &gt; 12:41:22.283  TEST: another round trip
  &gt; 12:41:24.303  TEST: another round trip
  &gt; 12:41:26.320  TEST: another round trip
  &gt; 12:41:28.353  TEST: another round trip
  &gt; 12:41:30.361  TEST: another round trip
  &gt; ----- Activity in Foreground
  &gt; 12:41:30.369  TEST: coroutine awake
  </code></pre>
  
  <p>How can I solve this?</p>
  
  <p>1 - Move the code from <code>init</code> to a <code>suspend fun start()</code> called by the activity inside a <code>lifecycleScope.launchWhenStarted</code>?  </p>
  
  <p>I get the same result. I thought <code>lifecycleScope</code> would cancel its child coroutines when it went to background, but I get the same Timber output with this approach. </p>
  
  <p>2 - Change my ViewModel code to:</p>
  
  <pre><code>private lateinit var job: Job
  
  suspend fun startEmitting() {
      job = viewModelScope.launch {
          Timber.i("coroutine awake")
          while (true){
              delay(2_000)
              Timber.i("another round trip")
          }
      }
  }
  fun cancelJob(){
      if(job.isActive){
          job.cancel()
      }
  }
  </code></pre>
  
  <p>And, in my Activity:</p>
  
  <pre><code>override fun onResume() {
      super.onResume()
      lifecycleScope.launch {
          viewModel.startEmitting()
      }
  }
  override fun onPause() {
      super.onPause()
      viewModel.cancelJob()
  }
  </code></pre>
  
  <p>Well it works but isn't the <code>viewModelScope</code> purpose to manage the <code>CoroutineScope</code> for me? I hate this cancelJob logic.</p>
  
  <p>What's the best approach to deal with this? </p>