Hi all, I have a general query to ask for Activit...
# android
Hi all, I have a general query to ask for Activity Contract API. Is there any way, we can write custom Contracts for 3rd Party Libraries that still uses
and overrides
. I am using Google Pay Wallet SDK and it has a function which simply accepts request code and internally calls
. Can I do something at my end to make the code more modular using ActivityContracts? Attaching sample code in thread.
😶 6
Copy code

AutoResolveHelper.resolveTask(    GoogleClient.googlePaymentsClient.loadPaymentData(request), this,

Copy code
override fun onActivityResult(
  requestCode: Int,
  resultCode: Int,
  data: Intent?
) {
  super.onActivityResult(requestCode, resultCode, data)
  when (requestCode) {
      when (resultCode) {
        RESULT_OK -> {
         // do something

        RESULT_CANCELED -> {
         // handle cancel

        AutoResolveHelper.RESULT_ERROR -> {
          //handle error
If, from Compose, you’re looking to incorporate third-party code that does not yet specify an ActivityResultContract, you can use the general contract:
Copy code
val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult(), onResult = { result ->
            /* Do something with result */
🙏 1
Then you simply launch the intent from the onClick:
Copy code
launcher.launch(Intent(context, SomeActivityClass::class.java))
💡 1