Created
September 16, 2017 20:42
-
-
Save rabidaudio/362812e877ab874a70197d8fa739f9cc to your computer and use it in GitHub Desktop.
Kotlin Coroutine Android examples
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
suspend fun showConfirmationDialog() = suspendCancellableCoroutine<Boolean> { cont -> | |
val dialog = AlertDialog.Builder(this) | |
.setMessage("Are you sure?") | |
.setPositiveButton("Yes", { _, _ -> cont.resume(true) }) | |
.setNegativeButton("No", { _, _ -> cont.resume(false) }) | |
.setCancelable(true) | |
.setOnCancelListener { cont.cancel() } | |
.create() | |
dialog.show() | |
cont.invokeOnCompletion { dialog.dismiss() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment