For coroutines, why ‘debug app’ gives different re...
# getting-started
h
For coroutines, why ‘debug app’ gives different result than ‘run app’ in logcat?
Copy code
class MainActivity : ComponentActivity() {
    private val TAG = "FUN"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {}
        GlobalScope.launch(Dispatchers.Main) {
            execute()
        }
    }
    private fun execute() {
        val parentJob = GlobalScope.launch(Dispatchers.Main) {
            Log.d(TAG, "Parent Started")
            val childJob = launch() {
                Log.d(TAG, "Child Started")
                delay(1000)
                Log.d(TAG, "Child Ended")
            }
            delay(3000)
            Log.d(TAG, "Parent Ended")
        }
    }
}
when we run and debug it, produces two different results? This result can also change depends on the no. of breakpoints used and where these breakpoints are used?
here is editor code for easy understanding