Skip to content

[image_picker] Mention launchMode: singleInstance in README #3759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

JeroenWeener
Copy link
Contributor

Users of the image picker are reporting issues for Android when setting the launchMode of the application activity to singleInstance. Namely, the image picker will always return RESULT_CANCELED. After investigation, it turned out that this problem is inherent by the way Android handles activities with this launch mode: singleInstance instructs the framework to open new activities in a new task. As activities cannot communicate between tasks, the image picker activity is unable to relay back the result to the calling activity.

This PR updates the README to mention this behavior and provide a workaround.

Closes 76856.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple formatting changes

@@ -41,6 +41,9 @@ It is no longer required to add `android:requestLegacyExternalStorage="true"` as
**Note:** Images and videos picked using the camera are saved to your application's local cache, and should therefore be expected to only be around temporarily.
If you require your picked image to be stored permanently, it is your responsibility to move it to a more permanent location.


**Note:** Launching the image picker from an `Activity` with `launchMode: singleInstance` will always return `RESULT_CANCELED`. In this launch mode, new activities are created in a separate [Task][2]. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity. To work around this problem, consider using `launchMode: singleTask` instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: break this up into multiple lines, similar to how we've formatted other blocks of text in this README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you want me to break up the lines? The way it is currently done in the README does not strike me as being consistent.
Should I limit lines to the 80 character count? Or should a start a newline when it makes sense for the flow of the text?

Option 1:

**Note:** Launching the image picker from an `Activity` with
`launchMode: singleInstance` will always return `RESULT_CANCELED`. In this
launch mode, new activities are created in a separate [Task][2]. As activities
cannot communicate between tasks, the image picker activity cannot send back
its eventual result to the calling activity. To work around this problem,
consider using `launchMode: singleTask` instead.

Option 2:

**Note:** Launching the image picker from an `Activity` with `launchMode: singleInstance` will always return `RESULT_CANCELED`.
In this launch mode, new activities are created in a separate [Task][2]. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity.
To work around this problem, consider using `launchMode: singleTask` instead.

Combining options 1 and 2:

**Note:** Launching the image picker from an `Activity` with
`launchMode: singleInstance` will always return `RESULT_CANCELED`.
In this launch mode, new activities are created in a separate [Task][2].
As activities cannot communicate between tasks, the image picker activity
cannot send back its eventual result to the calling activity.
To work around this problem, consider using `launchMode: singleTask` instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to keep lines to 80 characters in the READMEs; there's no enforcement so it's not always done consistently. Either the first or third option is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with option 3 here.

If you feel like making the rest of the readme fit this rule as well, that would be appreciated! You don't have to though.

@@ -41,6 +41,9 @@ It is no longer required to add `android:requestLegacyExternalStorage="true"` as
**Note:** Images and videos picked using the camera are saved to your application's local cache, and should therefore be expected to only be around temporarily.
If you require your picked image to be stored permanently, it is your responsibility to move it to a more permanent location.


**Note:** Launching the image picker from an `Activity` with `launchMode: singleInstance` will always return `RESULT_CANCELED`. In this launch mode, new activities are created in a separate [Task][2]. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity. To work around this problem, consider using `launchMode: singleTask` instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have 2 Notes, maybe it would be a good idea to add a section for Critical Information or something like that, to avoid collecting multiple "tag" endings on this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Would that still fall under the Android heading? Example:

### Android

...

#### Critical information
Images and videos picked using the camera are saved to your application's local cache, and should therefore be expected to only be around temporarily.
If you require your picked image to be stored permanently, it is your responsibility to move it to a more permanent location.

Launching the image picker from an `Activity` with `launchMode: singleInstance` will always return `RESULT_CANCELED`.
In this launch mode, new activities are created in a separate [Task][2]. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity.
To work around this problem, consider using `launchMode: singleTask` instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a subheading of Android as you've shown there would definitely be the right approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, even better might be to make each of these instead be a new #### subheading, and also move Handling MainActivity destruction on Android and Android Photo Picker up here as #### headings as well. Currently those are free-floating rather than under Android, even though they are Android-specific (and the first is a similar sort of note to this one).

@tarrinneal What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @stuartmorgan has the right idea here.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new text looks great! LGTM once Tarrin is happy with the structure.

@JeroenWeener JeroenWeener force-pushed the image-picker/mention-single-instance-in-readme branch from e9a0ad1 to 17a5a30 Compare April 21, 2023 09:52
@JeroenWeener JeroenWeener requested a review from tarrinneal April 21, 2023 11:16
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the extra work with this one!

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 21, 2023
@auto-submit auto-submit bot merged commit 528aa2d into flutter:main Apr 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 1, 2023
Roll Packages from 7e3f5da to de6131d (41 revisions)

flutter/packages@7e3f5da...de6131d

2023-05-01 [email protected] I122213 update non examples (flutter/packages#3846)
2023-04-29 [email protected] [go_router] Cleans up route match API and introduces dart fix (flutter/packages#3819)
2023-04-29 [email protected] [camerax] Add `LifecycleOwner` Proxy (flutter/packages#3837)
2023-04-29 [email protected] [file_selector] Add getDirectoryPaths implementation for Windows (flutter/packages#3704)
2023-04-29 [email protected] [various] Update Android example min SDKs (flutter/packages#3847)
2023-04-28 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.2.12 to 2.3.2 (flutter/packages#3838)
2023-04-28 [email protected] [camerax] Implement Image Streaming (flutter/packages#3454)
2023-04-28 [email protected] [various] update agp and gradle for all examples in packages (flutter/packages#3822)
2023-04-28 [email protected] Update xcode to 14c18 (flutter/packages#3774)
2023-04-28 [email protected] [camera_android] Add NV21 as an image stream format #3277 (flutter/packages#3639)
2023-04-28 [email protected] [go_router] Remove unused navigator keys (flutter/packages#3708)
2023-04-28 [email protected] [image_picker] Move I/O operations to a separate thread (flutter/packages#3506)
2023-04-28 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump org.jetbrains.kotlin:kotlin-gradle-plugin from 1.8.20 to 1.8.21 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#3824)
2023-04-28 [email protected] [pigeon] Reland: Add an initial example app (flutter/packages#3832)
2023-04-28 [email protected] Roll Flutter from c9004ff to 66fa4c5 (68 revisions) (flutter/packages#3830)
2023-04-28 [email protected] [various] Conditionalize the namespace in all Android plugins (flutter/packages#3836)
2023-04-27 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump com.android.billingclient:billing from 5.1.0 to 5.2.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#3672)
2023-04-27 [email protected] [auick_action_ios] Retries multiple times to not fail ci when there is a flake (flutter/packages#3823)
2023-04-26 [email protected] Swap some iOS package CODEOWNERS (flutter/packages#3793)
2023-04-26 [email protected] [various] Add `targetCompatibility` to build.gradle (flutter/packages#3825)
2023-04-26 [email protected] [various] Set cmake_policy versions (flutter/packages#3828)
2023-04-26 [email protected] [path_provider] Allow `win32` up to version 4.x (flutter/packages#3820)
2023-04-26 [email protected] [tool] Move Android lint checks (flutter/packages#3816)
2023-04-25 [email protected] [google_maps_flutter_android] Fix Android lint warnings (flutter/packages#3751)
2023-04-25 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.5.0 to 1.6.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#3381)
2023-04-25 [email protected] Update test golden images for the latest Skia roll (flutter/packages#3787)
2023-04-25 [email protected] [various] Adds Android namespace (flutter/packages#3791)
2023-04-25 [email protected] [shared_preferences] Update gradle/agp in example apps (flutter/packages#3809)
2023-04-24 [email protected] [go_router] Adds name to TypedGoRoute (flutter/packages#3702)
2023-04-22 [email protected] [webview_flutter] Adds support to receive permission requests (flutter/packages#3543)
2023-04-21 [email protected] [google_sign_in] Fix Android Java warnings (flutter/packages#3762)
2023-04-21 [email protected] [local_auth] Fix enum return on Android (flutter/packages#3780)
2023-04-21 [email protected] [pigeon] Warn when trying to use enums in collections (flutter/packages#3782)
2023-04-21 [email protected] [webview_flutter_android] [webview_flutter_wkwebview] Platform implementations for supporting permission requests (flutter/packages#3792)
2023-04-21 [email protected] [pigeon] Update for compatibility with a future change to the analyzer. (flutter/packages#3789)
2023-04-21 [email protected] [camera_android] Fix Android lint warnings  (flutter/packages#3716)
2023-04-21 [email protected] [webview_flutter_platform_interface] Adds method to receive permission requests (flutter/packages#3767)
2023-04-21 [email protected] [image_picker_ios] In unit test write and read kCGImagePropertyExifUserComment property (flutter/packages#3783)
2023-04-21 [email protected] [go_router_builder] Fixed the return value of the generated push method (flutter/packages#3650)
2023-04-21 [email protected] [image_picker] Mention `launchMode: singleInstance` in README (flutter/packages#3759)
2023-04-21 [email protected] Revert "[pigeon] Add an initial example app" (flutter/packages#3785)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
...
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
…r#3759)

Users of the image picker are reporting issues for Android when setting the `launchMode` of the application activity to `singleInstance`. Namely, the image picker will always return `RESULT_CANCELED`. After investigation, it turned out that this problem is inherent by the way Android handles activities with this launch mode: `singleInstance` instructs the framework to open new activities in a new task. As activities cannot communicate between tasks, the image picker activity is unable to relay back the result to the calling activity.

This PR updates the README to mention this behavior and provide a workaround.

Closes [76856](flutter/flutter#76856).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: image_picker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[image_picker] Image picker returns null when selecting image from other apps when using singleInstance
3 participants