I need help with detecting when a user comes back to my app after opening an email client. I’m using Jetpack Compose and trying to execute some code when the user returns from the email app.
Here’s my current setup:
val emailLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = { activityResult ->
Log.d("MyApp", "Result code: ${activityResult.resultCode}")
// Want to run custom logic here
}
)
And I’m launching the email app like this:
Button(
onClick = {
val emailIntent = Intent(Intent.ACTION_MAIN).apply {
addCategory(Intent.CATEGORY_APP_EMAIL)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
emailLauncher.launch(emailIntent)
}
) {
Text("Open Email App")
}
The problem is that the callback fires immediately when I leave my app (showing result code 0), but when I navigate back from the email application, the onResult callback doesn’t get triggered again. How can I properly detect when the user returns to my app from the email client?