android-client
android-client copied to clipboard
Cancel coroutine started in startContext when stopContext is invoked
According to the Kotlin docs, "a global CoroutineScope not bound to any job. Global scope is used to launch top-level coroutines which are operating on the whole application lifetime and are not cancelled prematurely. Active coroutines launched in GlobalScope do not keep the process alive. They are like daemon threads."
This implies that, after Client.startContex() is invoked, the coroutine launched lays dormant and consumes system resources. Which is not optimal. The best thing to do in my opinion is to cancell the coroutine when it is not active.