Created
May 1, 2020 14:13
-
-
Save Dhaval2404/7e34fb4bf34cb46f521d6a72f00e637e to your computer and use it in GitHub Desktop.
Inline Activity Result
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
package com.github.dhaval2404.imagepicker.util | |
import android.content.Intent | |
import androidx.activity.result.ActivityResult | |
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.fragment.app.Fragment | |
/** | |
* Inline Activity Result | |
* | |
* @author Dhaval Patel | |
* @version 2.0 | |
* @since 29 April 2020 | |
*/ | |
fun AppCompatActivity.startActivityForResult( | |
intent: Intent, | |
listener: (Int, Intent?) -> Unit? | |
) { | |
prepareCall(StartActivityForResult()) { result: ActivityResult -> | |
listener.invoke(result.resultCode, result.data) | |
}.launch(intent) | |
} | |
fun Fragment.startActivityForResult(intent: Intent, listener: (Int, Intent?) -> Unit?) { | |
prepareCall(StartActivityForResult()) { result: ActivityResult -> | |
listener.invoke(result.resultCode, result.data) | |
}.launch(intent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required Gradle: