I had the exact same problem and found out there are differences between different mail apps. When I pick Samsung Mail from the chooser I do not encounter this problem and I am able to return to my app by pressing back. However, when I choose Gmail from the chooser I encounter the same problem as you describe.
I have tried nearly every possible solution I could find on StackOverflow, but this seemed to be the only working answer: https://stackoverflow.com/a/28190257/11642110 I will post the code in case the link dies.
Java:
Intent emailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"));
PackageManager packageManager = getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(emailIntent, 0);
if (resolveInfoList.size() > 0) {
ResolveInfo resolveInfo = resolveInfoList.get(0);
// First create an intent with only the package name of the first registered email app
// and build a picked based on it
Intent chooserIntent = Intent.createChooser(packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName), "");
// Then create a list of LabeledIntent for the rest of the registered email apps
List<LabeledIntent> intentList = new ArrayList<>();
for (int i = 1; i < resolveInfoList.size(); i++) {
// Extract the label and repackage it in a LabeledIntent
resolveInfo = resolveInfoList.get(i);
String packageName = resolveInfo.activityInfo.packageName;
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
intentList.add(new LabeledIntent(intent, packageName, resolveInfo.loadLabel(packageManager), resolveInfo.icon));
}
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[0]);
// Add the rest of the email apps to the picker selection
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(chooserIntent);
}
Kotlin:
val emailIntent = Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"))
val packageManager = context?.packageManager
val resolveInfoList = packageManager?.queryIntentActivities(emailIntent, 0)
if (!resolveInfoList.isNullOrEmpty()) {
var resolveInfo = resolveInfoList[0]
// First create an intent with only the package name of the first registered email app
// and build a picked based on it
val chooserIntent = Intent.createChooser(packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName), "")
// Then create a list of LabeledIntent for the rest of the registered email apps
val intentList: MutableList<LabeledIntent> = ArrayList()
for (i in 1 until resolveInfoList.size) {
// Extract the label and repackage it in a LabeledIntent
resolveInfo = resolveInfoList[i]
val packageName = resolveInfo.activityInfo.packageName
val intent = packageManager.getLaunchIntentForPackage(packageName)
intentList.add(LabeledIntent(intent, packageName, resolveInfo.loadLabel(packageManager), resolveInfo.icon))
}
// Add the rest of the email apps to the picker selection
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toTypedArray())
startActivity(chooserIntent)
}