Skip to content

Instantly share code, notes, and snippets.

@teegarcs
Created August 16, 2020 12:03
Show Gist options
  • Save teegarcs/94277bcdc9f7da4745aefb4c02faaf32 to your computer and use it in GitHub Desktop.
Save teegarcs/94277bcdc9f7da4745aefb4c02faaf32 to your computer and use it in GitHub Desktop.
class MessageContract : ActivityResultContract<Unit, String>() {
companion object {
const val MESSAGE = "MESSAGE_CONTRACT"
}
override fun createIntent(context: Context, input: Unit?) =
Intent(context, MessageActivity::class.java)
/**
* Gets hit when the MessageActivity is closed. The result can
* then be parsed and set to the String that our contract is
* looking for.
*/
override fun parseResult(resultCode: Int, intent: Intent?): String {
val message = intent?.getStringExtra(MESSAGE)
return if (message.isNullOrEmpty()) {
"No Message Provided"
} else {
message
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment