From bad38b7fff0f1899109c0833d45a34b21d7b3603 Mon Sep 17 00:00:00 2001 From: mrjo118 Date: Sat, 24 Oct 2026 17:25:18 +0100 Subject: [PATCH] Android: Fixes #8099: Fix data share not working after leaving by back button (#16906) --- .../net/cozic/joplin/share/SharePackage.java | 20 ++++++++++--------- packages/app-mobile/root.tsx | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/share/SharePackage.java b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/share/SharePackage.java index 6036c4c319..8595962885 100644 --- a/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/share/SharePackage.java +++ b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/share/SharePackage.java @@ -45,7 +45,7 @@ public class SharePackage implements ReactPackage { } public static class ShareModule extends ReactContextBaseJavaModule implements ActivityEventListener, LifecycleEventListener { - private boolean handledStartIntent = false; + private Activity handledStartIntentActivity = null; private Intent receivedShareIntent = null; ShareModule(@NonNull ReactApplicationContext reactContext) { @@ -206,15 +206,16 @@ public class SharePackage implements ReactPackage { @Override public void onHostResume() { - if (this.getCurrentActivity() != null) { - Intent intent = this.getCurrentActivity().getIntent(); - if (this.handledStartIntent) { - // sometimes onHostResume is fired after onNewIntent - // and we only care about the activity intent when the first time app opens - return; + Activity currentActivity = this.getCurrentActivity(); + if (currentActivity != null && currentActivity != this.handledStartIntentActivity) { + // Read the start intent once per activity. A later onNewIntent may be + // followed by onHostResume, while a share after Back may create a new activity. + this.handledStartIntentActivity = currentActivity; + Intent intent = currentActivity.getIntent(); + // Recents can relaunch the original share intent, but it is not a new share. + if (intent != null && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { + this.onNewIntent(intent); } - this.handledStartIntent = true; - this.onNewIntent(intent); } } @@ -223,6 +224,7 @@ public class SharePackage implements ReactPackage { @Override public void onHostDestroy() { + this.handledStartIntentActivity = null; } } } diff --git a/packages/app-mobile/root.tsx b/packages/app-mobile/root.tsx index 1bd3d665d6..bbecef54ab 100644 --- a/packages/app-mobile/root.tsx +++ b/packages/app-mobile/root.tsx @@ -504,6 +504,11 @@ class AppComponent extends React.Component } this.urlOpenListener_ = Linking.addEventListener('url', this.handleOpenURL_); + // A new activity can remount this component with biometrics already done. + // Its native share event may have arrived before the ShareExtension listener was attached. + if (this.props.biometricsDone) { + void this.handleShareData(); + } BackButtonService.initialize(this.backButtonHandler_);