Created
August 16, 2020 12:03
-
-
Save teegarcs/94277bcdc9f7da4745aefb4c02faaf32 to your computer and use it in GitHub Desktop.
This file contains 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 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