Created
May 21, 2022 18:56
-
-
Save prateek54/027ca2f5ca00653dfe4dda76640fab4c to your computer and use it in GitHub Desktop.
Custom Result Contract Kotlin Class
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 CustomContract : ActivityResultContract<String, String?>() { | |
const val DATA = "data" | |
const val INPUT_DATA = "input_data" | |
override fun createIntent(context: Context, input: String?): Intent { | |
val intent = Intent(context, DummyResultActivity::class.java) | |
intent.putExtra(INPUT_DATA, input) | |
return intent | |
} | |
override fun parseResult(resultCode: Int, intent: Intent?): String? { | |
return when (resultCode) { | |
//Transforming our result to required format before returning it | |
Activity.RESULT_OK -> intent?.getStringExtra(DATA) | |
else -> null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment