Given this:
fun sendEmailAction(context: Context?, subject: String, body: String, emailAddress: String) {
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", emailAddress, null))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
emailIntent.putExtra(Intent.EXTRA_TEXT, body)
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress)
val emailChooser = Intent.createChooser(emailIntent, context?.resources?.getString(R.string.contactByEmail_action))
startActivityForResult(emailChooser, EMAIL_REQUEST)
}
I open a chooser for someone to send an email. But if the user presses back, my starting app is hidden (soft quit). If I add this :
emailChooser.flags = FLAG_ACTIVITY_NEW_TASK
Then pressing back brings me back to my app as desired, but leaves the mail app open (behind), because, as per the flag, it's a new task.
Is there a way to keep the mail activity in the starting app and allow the back button to be pressed to return to the calling activity? If so, how?