From 4926c0f8bd99ac61e5208e3410182be97ec0c2a4 Mon Sep 17 00:00:00 2001 From: Camille Simon <43054281+camsim99@users.noreply.github.com> Date: Tue, 24 Sep 2024 04:42:24 -0700 Subject: [PATCH] [quick_actions] Add guidance for correcting task management/back press behavior for apps with launcher activities (#7686) ### What Adds a note about correcting the task management/back press behavior for apps that use launcher activities to the `README`. Fixes https://github.com/flutter/flutter/issues/152883. ### Why If apps use a launcher activity, then launching shortcuts created by the plugin may not behave as expected because the plugin expects to launch the main `FlutterActivity`, for which it configures the launch mode, but instead launches the launcher activity, which it does not account for. To fix this, the launcher activity itself needs to have a launch mode configuration that makes sense for the app. This involves changing the launch mode of the launcher activity in the manifest and/or using the right `Intent` flags to launch the main `FlutterActivity`. From my work on the issue linked above, I found that if the launcher activity only launches the main `FlutterActivity` without any additional relevant logic, to maintain the exact same behavior of the plugin with/without a launcher activity, the launcher activity can use the `singleInstance` launch mode. So, I included a note about this. However, in more complex launcher activities, like b/357028168 that inspired the original issue, other modes may need to be used. --- .../quick_actions/quick_actions/CHANGELOG.md | 3 ++- .../quick_actions/quick_actions/README.md | 3 +++ .../quick_actions/quick_actions/pubspec.yaml | 2 +- .../quick_actions_android/CHANGELOG.md | 4 +++ .../quick_actions_android/README.md | 25 +++++++++++++++++++ .../quick_actions_android/pubspec.yaml | 2 +- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/quick_actions/quick_actions/CHANGELOG.md b/packages/quick_actions/quick_actions/CHANGELOG.md index 45390ea9ad9a..8a2bccc7641e 100644 --- a/packages/quick_actions/quick_actions/CHANGELOG.md +++ b/packages/quick_actions/quick_actions/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 1.0.8 * Updates minimum supported SDK version to Flutter 3.19/Dart 3.3. +* Adds reference to `quick_actions_android` README in the Android section of the README. ## 1.0.7 diff --git a/packages/quick_actions/quick_actions/README.md b/packages/quick_actions/quick_actions/README.md index ad9b2a8c3b97..d776be2a3bf7 100644 --- a/packages/quick_actions/quick_actions/README.md +++ b/packages/quick_actions/quick_actions/README.md @@ -52,3 +52,6 @@ If the drawables used as icons are not referenced other than in your Dart code, you may need to [explicitly mark them to be kept](https://developer.android.com/studio/build/shrink-code#keep-resources) to ensure that they will be available for use in release builds. + +For more information on using this package on Android, see the +[`quick_actions_android` README](https://github.com/flutter/packages/blob/main/packages/quick_actions/quick_actions_android/README.md). diff --git a/packages/quick_actions/quick_actions/pubspec.yaml b/packages/quick_actions/quick_actions/pubspec.yaml index 53a1a6a5e33c..e01c0b3b478f 100644 --- a/packages/quick_actions/quick_actions/pubspec.yaml +++ b/packages/quick_actions/quick_actions/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for creating shortcuts on home screen, also known as Quick Actions on iOS and App Shortcuts on Android. repository: https://github.com/flutter/packages/tree/main/packages/quick_actions/quick_actions issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+quick_actions%22 -version: 1.0.7 +version: 1.0.8 environment: sdk: ^3.3.0 diff --git a/packages/quick_actions/quick_actions_android/CHANGELOG.md b/packages/quick_actions/quick_actions_android/CHANGELOG.md index 4ac6505b6131..37c75366b57f 100644 --- a/packages/quick_actions/quick_actions_android/CHANGELOG.md +++ b/packages/quick_actions/quick_actions_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.16 + +* Updates README to include guidance on using the plugin with a launcher activity. + ## 1.0.15 * Updates lint checks to ignore NewerVersionAvailable. diff --git a/packages/quick_actions/quick_actions_android/README.md b/packages/quick_actions/quick_actions_android/README.md index cb4a8e08826a..5c7be83e8a16 100644 --- a/packages/quick_actions/quick_actions_android/README.md +++ b/packages/quick_actions/quick_actions_android/README.md @@ -11,6 +11,30 @@ so you do not need to add it to your `pubspec.yaml`. However, if you `import` this package to use any of its APIs directly, you should add it to your `pubspec.yaml` as usual. +## Usage with launcher activities + +If your app implements an activity that launches the main `FlutterActivity` +(`MainActivity.java`/`MainActivity.kt` by default), then you may need to change +the launch mode of your launcher activity and/or modify the `Intent` flags used +to launch the main `FlutterActivity` in order to achieve the desired back press +behavior and task management. + +If your launcher activity only launches the main `FlutterActivity` without any +additional relevant logic (like the code sample provided in the description of +https://github.com/flutter/flutter/issues/152883), to have your app maintain the +same behavior of `quick_actions_android` with/without a launcher activity, set +the launch mode of your launcher activity to `singleInstance` in +`your_app/android/app/src/mainAndroidManifest.xml`: + +```xml + +``` + +See the [Tasks and the back stack][4] Android documentation for more information +on the different launch modes and `Intent` flags you may need. + ## Contributing If you would like to contribute to the plugin, check out our [contribution guide][3]. @@ -18,3 +42,4 @@ If you would like to contribute to the plugin, check out our [contribution guide [1]: https://pub.dev/packages/quick_actions [2]: https://flutter.dev/to/endorsed-federated-plugin [3]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md +[4]: https://developer.android.com/guide/components/activities/tasks-and-back-stack#TaskLaunchModes diff --git a/packages/quick_actions/quick_actions_android/pubspec.yaml b/packages/quick_actions/quick_actions_android/pubspec.yaml index 0ac026ee529b..9f2dd2f70987 100644 --- a/packages/quick_actions/quick_actions_android/pubspec.yaml +++ b/packages/quick_actions/quick_actions_android/pubspec.yaml @@ -2,7 +2,7 @@ name: quick_actions_android description: An implementation for the Android platform of the Flutter `quick_actions` plugin. repository: https://github.com/flutter/packages/tree/main/packages/quick_actions/quick_actions_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 1.0.15 +version: 1.0.16 environment: sdk: ^3.4.0