Created
January 28, 2021 02:01
-
-
Save jerry-jeon/ae54d61cf037f113fd729b3f2e11d757 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 OwnSolutionActivity : Activity() { | |
private lateinit var binding: ActivityOwnSolutionBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityOwnSolutionBinding.inflate(layoutInflater) | |
binding.button.setOnClickListener { | |
val intent = Intent(Intent.ACTION_GET_CONTENT) | |
intent.type = "image/*" | |
startActivityForResultAndHandle(intent) { resultCode, intent -> | |
if(resultCode == RESULT_OK) { | |
binding.image.load(intent?.data) | |
} | |
} | |
} | |
setContentView(binding.root) | |
} | |
private var handleResult: ((Int, Intent?) -> Unit)? = null | |
private fun startActivityForResultAndHandle(intent: Intent, lambda: ((Int, Intent?) -> Unit)) { | |
handleResult = lambda | |
startActivityForResult(intent, 300) | |
} | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
handleResult?.invoke(resultCode, data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment