MainScope

fun MainScope(): CoroutineScope (source)

Creates the main CoroutineScope for UI components.

Example of use:

class MyAndroidActivity {
  private val scope = MainScope()

  override fun onDestroy() {
    super.onDestroy()
    scope.cancel()
  }
}

The resulting scope has SupervisorJob and Dispatchers.Main context elements. If you want to append additional elements to the main scope, use CoroutineScope.plus operator: val scope = MainScope() + CoroutineName("MyActivity").