Skip to content

Instantly share code, notes, and snippets.

@k0siara
Created November 5, 2022 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0siara/e7eb0c4dca0088596202e5a9cdfd587f to your computer and use it in GitHub Desktop.
Save k0siara/e7eb0c4dca0088596202e5a9cdfd587f to your computer and use it in GitHub Desktop.
BetterMyFragment.kt
class MyFragment : Fragment(R.layout.my_layout) {
fun onSomeAction() {
coroutineScope.launch {
// Code A
when (val dialogResult = showDialogAndAwaitResult()) {
DialogResult.Ok -> {
// Code C
}
DialogResult.Cancel -> {
// Code D
}
}
// Code B
}
}
private suspend fun showDialogAndAwaitResult(): DialogResult {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment