I have a main activity which serves as an entry point to call different activities, depending on condition. Among others, I use Firebase Auth to manage user sign in:
startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN)
I overwrite onActivityResult()
to distinguish the returned intent/data, for example:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQUEST_CODE_1 -> {
// update UI and stuff
}
RC_SIGN_IN -> {
// check Firebase log in
}
// ...
}
}
With the Activity Result APIs which is strongly recommended by the documentation, I get that I should make prepareCall()
before ActivityResultLauncher
and to make sure the activity is in created state when I launch, but I still don't understand how to handle multiple activity results gracefully (at least, in one place) like in onActivityResult()
.
Looking at this article, it seems I need to implement multiple child inner classes of ActivityResultContract
type (therefore multiple prepareCall()
's?), because they are suppose to be different contracts, am I correct? Can someone please show me some skeleton example that mirrors the above onActivityResult()
logic?
'android.content.Intent intent, int requestCode'
as parameters? – Ease