-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Fix IllegalStateException being thrown in Android implementation when switching activities. #4319
Conversation
backgroundHandlerThread.start(); | ||
} catch (IllegalThreadStateException e) { | ||
// Ignore exception in case the thread has already started. | ||
if (backgroundHandlerThread == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a lifecycle test to avoid re-involved with the same issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a unit-test which tests for the if
statement. However I am not sure how we could add a test to verify that we don't add implementation of listening to lifecycle events in the future.
Do you have some insights on how this could be accomplished?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an observer WidgetsBindingObserver
in a Flutter App, then override the didChangeAppLifecycleState
might be a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capturing from a separate discussion, verifying that the core classes (Camera
, CameraPlugin
) are not instanceof LifecycleObserver
seems like a possible approach, even if it's not foolproof (e.g., a composed object could implement it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, it could just return earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (backgroundHandlerThread != null) {
return;
}
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
@blasten @bparrishMines Could one of you review this? It fixes a P2 regression. |
packages/camera/camera/CHANGELOG.md
Outdated
@@ -1,3 +1,8 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
1a4add1
to
13976d3
Compare
According to feedback from @blasten on PR, the following changes are made: - Removed an obsolete empty line in the CHANGELOG.md; - Return early from the `startBackgroundThread` function when the `backgroundHandlerThread is not `null`. This simplifies the method making it easier to read and understand.
13976d3
to
9561993
Compare
…plementation when switching activities. (flutter/plugins#4319)
…plementation when switching activities. (flutter/plugins#4319) (#90857)
* master: [google_maps_flutter] Add Marker drag events (flutter#2838) [flutter_plugin_tools] Validate pubspec description (flutter#4396) Add file_selector to the repo list (flutter#4395) [in_app_purchase] Fix in_app_purchase_android/README.md (flutter#4363) [google_maps_flutter_web] Add Marker drag events (flutter#4385) [webview_flutter] Fixed todos in FlutterWebView.java (flutter#4394) Handle `PurchaseStatus.restored` correctly in example. (flutter#4393) Handle restored purchases in iOS example app (flutter#4392) [file_selector] Remove custom analysis options (flutter#4382) [flutter_plugin_tools] Check licenses in Kotlin (flutter#4373) Fixed _CastError when running example App (flutter#4390) [in_app_purchase] Ensure the introductoryPriceMicros field is transported as a String. (flutter#4370) Load navigation controls immediately. (flutter#4377) [camera] Fix IllegalStateException being thrown in Android implementation when switching activities. (flutter#4319) # Conflicts: # packages/webview_flutter/webview_flutter/CHANGELOG.md # packages/webview_flutter/webview_flutter_android/CHANGELOG.md
…plementation when switching activities. (flutter/plugins#4319) (flutter#90857)
…tion when switching activities. (flutter#4319)
…tion when switching activities. (flutter#4319)
…tion when switching activities. (flutter#4319)
This PR removes the lifecycle hooks from the Android implementation. I have a feeling these were added by accident during the recent refactor, as the example app already puts this responsibility on the user of the plugin.
This is also described in the readme: https://github.com/flutter/plugins/tree/master/packages/camera/camera#handling-lifecycle-states
This should fix the issue with the IllegalStateException being thrown when switching to a different activity, for example when using
camera
in combination withimage_picker
, as can be seen in the issue linked below:Relevant issues:
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).