Last active
May 13, 2024 08:41
-
-
Save af2905/d823b11ca73e2ca79cb082608cc3f7b2 to your computer and use it in GitHub Desktop.
tricky questions_full_code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
CoroutinestrickyquestionsTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
Box(modifier = Modifier.wrapContentSize()) { | |
Button( | |
onClick = { | |
startCoroutine() | |
} | |
) { | |
Text(text = "Start coroutine") | |
} | |
} | |
} | |
} | |
} | |
} | |
private fun startCoroutine() { | |
val myScope: CoroutineScope = CoroutineScope(context = Job()) | |
myScope.launch { | |
delay(500L) | |
println("A") | |
coroutineScope { | |
launch { | |
delay(1000L) | |
println("B") | |
} | |
delay(100L) | |
println("C") | |
} | |
println("D") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment