Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created May 1, 2020 22:39
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 wajahatkarim3/118dc4eb039748ef5a4fe6ab0f6b2b61 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/118dc4eb039748ef5a4fe6ab0f6b2b61 to your computer and use it in GitHub Desktop.
class SimpleContract : ActivityResultContract<Integer, String?>() {
override fun createIntent(context: Context, input: Integer?): Intent {
var intent = Intent(context, MyChildActivity::class.java)
intent.putExtra("myInputKey", input)
return intent
}
override fun parseResult(resultCode: Int, intent: Intent?): String? = when
{
resultCode != Activity.RESULT_OK -> null // Return null, if action is cancelled
else -> intent?.getStringExtra("data") // Return the data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment