Skip to content

Commit

Permalink
[quick_actions] Add guidance for correcting task management/back pres…
Browse files Browse the repository at this point in the history
…s 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 flutter/flutter#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.
  • Loading branch information
camsim99 authored Sep 24, 2024
1 parent 21d99dc commit 4926c0f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/quick_actions/quick_actions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions packages/quick_actions/quick_actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion packages/quick_actions/quick_actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/quick_actions/quick_actions_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
25 changes: 25 additions & 0 deletions packages/quick_actions/quick_actions_android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,35 @@ 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
<activity
...
android:launchMode="singleInstance">
```

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].

[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
2 changes: 1 addition & 1 deletion packages/quick_actions/quick_actions_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4926c0f

Please sign in to comment.