From 4857e75200303e8630a7bba61233bbdacfac1d37 Mon Sep 17 00:00:00 2001 From: leonardo-oliveir-a Date: Tue, 26 May 2026 21:08:03 +0100 Subject: [PATCH] feat(share_plus): add FLAG_ACTIVITY_NEW_TASK to chooser intent on Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When share_plus opens the share sheet and the user picks a target app (WhatsApp, Telegram, Drive, etc.), the target activity is currently stacked on top of the calling app's task. In the recents switcher this shows up as a single entry for the calling app with the target app visible inside it — inconsistent with how native Android apps like Google Keep or Instagram handle share, where the target appears as a separate recents entry. Adding `Intent.FLAG_ACTIVITY_NEW_TASK` to the chooser intent before `startActivity` instructs Android to launch the target in its own task, matching the behavior users expect from system share. This unblocks issue #2267 (open since Oct 2023) and addresses the underlying mechanism in #2682. Equivalent fix attempted in #3751 but that PR was closed minutes after creation by a CI bot complaining about the title format. The change is one-line behavior addition with no API surface change. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../kotlin/dev/fluttercommunity/plus/share/Share.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt index fb6a107988..6c2389812a 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt @@ -131,6 +131,16 @@ internal class Share( Intent.createChooser(shareIntent, title) } + // Launch the destination app in its own task so it appears as a + // separate entry in the recents switcher instead of being stacked + // on top of the calling app's task. Without this flag the target + // (WhatsApp, Telegram, Drive, etc.) inherits the caller's task — + // user sees a single recents entry for the caller with the target + // visible inside, which is confusing and inconsistent with how + // Android share works for most native apps (e.g. Google Keep, + // Instagram). See plus_plugins issue #2267. + chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + // Grant permissions to all apps that can handle the files shared if (fileUris != null) { val resInfoList = getContext().packageManager.queryIntentActivities(