title: If lifecycleScope is supervisor, why its child coroutine's failure causes the app crash?
body: <p>I'm new to Kotlin coroutines and try to understand supervision. As docs say:</p>
  
  <blockquote>
    <p>A failure or cancellation of a child does not cause the supervisor job to fail and does not affect its other children.</p>
  </blockquote>
  
  <hr>
  
  <p>Ok, I've written the following code for JVM:</p>
  
  <pre><code>@JvmStatic
  fun main(args: Array&lt;String&gt;) = runBlocking {
      val supervisorScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
  
      // Coroutine #1
      supervisorScope.launch {
          println("Coroutine #1 start")
          delay(100)
          throw RuntimeException("Coroutine #1 failure")
      }
  
      // Coroutine #2
      supervisorScope.launch {
          for (i in 0 until 5) {
              println("Coroutine #2: $i")
              delay(100)
          }
      }
  
      supervisorScope.coroutineContext[Job]!!.children.forEach { it.join() }
  }
  </code></pre>
  
  <p>Here everything is fine, <code>Coroutine #1</code> failure neither affect the parent, nor the <code>Coroutine #2</code>. That's the purpose of supervision. The output is consistent to the docs:</p>
  
  <pre><code>Coroutine #1 start
  Coroutine #2: 0
  Coroutine #2: 1
  Exception in thread "DefaultDispatcher-worker-1" java.lang.RuntimeException: Coroutine #1 failure
      at supervisor.SupervisorJobUsage$main$1$1.invokeSuspend(SupervisorJobUsage.kt:16)
      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
      at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
  Coroutine #2: 2
  Coroutine #2: 3
  Coroutine #2: 4
  
  Process finished with exit code 0
  </code></pre>
  
  <hr>
  
  <p>But then I've written almost the same code for Android:</p>
  
  <pre><code>class CoroutineJobActivity : AppCompatActivity() {
  
      private val TAG = "CoroutineJobActivity"
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          testSupervisorScope()
      }
  
      private fun testSupervisorScope() {
          // Coroutine #1
          lifecycleScope.launch(Dispatchers.Default) {
              Log.d(TAG, "testSupervisorScope: Coroutine #1 start")
              delay(100)
              throw RuntimeException("Coroutine #1 failure")
          }
  
          // Coroutine #2
          lifecycleScope.launch(Dispatchers.Default) {
              for (i in 0 until 5) {
                  Log.d(TAG, "testSupervisorScope: Coroutine #2: $i")
                  delay(100)
              }
          }
      }
  }
  </code></pre>
  
  <p>The output is unexpected, because <strong><code>Coroutine #2</code> doesn't finish its work due to the app crash.</strong></p>
  
  <pre><code>testSupervisorScope: Coroutine #1 start
  testSupervisorScope: Coroutine #2: 0
  testSupervisorScope: Coroutine #2: 1
  testSupervisorScope: Coroutine #2: 2
  FATAL EXCEPTION: DefaultDispatcher-worker-2
      Process: jp.neechan.kotlin_coroutines_android, PID: 23561
      java.lang.RuntimeException: Coroutine #1 failure
          at jp.neechan.kotlin_coroutines_android.coroutinejob.CoroutineJobActivity$testSupervisorScope$1.invokeSuspend(CoroutineJobActivity.kt:25)
          at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
          at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
          at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
  </code></pre>
  
  <hr>
  
  <p>Although <code>lifecycleScope.coroutineContext</code> is <code>SupervisorJob() + Dispatchers.Main.immediate</code>, here I see that failure of child coroutine affected the parent and other children.</p>
  
  <p>So what is a purpose of supervising <code>lifecycleScope</code>?</p>