[image_picker] Fixes activity leak#4439
Conversation
|
Thanks for the submission! You removed most of the PR checklist; it's there for a reason, and many of the items you removed are not optional. I'm going to mark this as a draft for now; please restore the original checklist, address the missing elements, then remove the draft designation so that we can get it reviewed. |
f565703 to
0b4c890
Compare
Sorry, I misunderstood. Those removed items are restored now. |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
- I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
- I updated CHANGELOG.md to add a description of the change.
This change needs these steps. Please see the first link there.
- I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
As discussed at length in the contributing docs, this step is required.
fc3b3a6 to
b096c1c
Compare
Just simply recycling resources in tearDown, I don't think there is a need for test cases. It is hard to add tests here. Any guidance? Thanks. @stuartmorgan |
You appear to believe that the bug needs to be fixed, since you filed an issue and submitted a PR. Why wouldn't you want to prevent it from regressing again in the future? But regardless, PRs here follow Flutter policy (which you've indicated in the checklist that you have read), and personal opinions about the value of tests isn't one of the exemptions listed in that policy.
There are lots of possible ways to test this. In order to make the code as future-proof as possible, I would probably move all of this activity-lifetime-bound state into a helper object, so that /cc @blasten in case he has alternate preferences. |
|
@stuartmorgan Thank you for your rapid reply and patient. |
c9cfde7 to
68f0c30
Compare
c52d2de to
c7108c1
Compare
b966ec3 to
1067b74
Compare
stuartmorgan-g
left a comment
There was a problem hiding this comment.
This change needs a version bump since it's changing code behavior, but otherwise looks good to me at a high level.
@blasten Please assign a primary reviewer from the Android side.
|
|
||
| * Updates Android compileSdkVersion to 31. | ||
| * Fix iOS RunnerUITests search paths. | ||
| * Fix Activity leak |
There was a problem hiding this comment.
Please add the missing period at the end.
Also this should be "Fixes" per the repo's new CHANGELOG style guide. (It would be great if you could update the line above it the same way.)
| channel = null; | ||
| application.unregisterActivityLifecycleCallbacks(observer); | ||
| application = null; | ||
| activityState.release(); |
There was a problem hiding this comment.
Doesn't this need a null check?
2ec0b45 to
60559bb
Compare
1860782 to
c113535
Compare
|
@blasten Ping for second review here? |
| // V1 embedding setup for activity listeners. | ||
| application.registerActivityLifecycleCallbacks(observer); | ||
| registrar.addActivityResultListener(delegate); | ||
| registrar.addRequestPermissionsResultListener(delegate); |
There was a problem hiding this comment.
I will just throw here. We planned on removing the v1 embedding this quarter. cc @GaryQian
There was a problem hiding this comment.
It is more appropriate to remove the v1 embedding in another PR.
| } | ||
| } | ||
|
|
||
| ActivityState(final ImagePickerDelegate delegate, final Activity activity) { |
There was a problem hiding this comment.
this needs javadocs. when is this constructor preferred over the other one?
| // This is null when not using v2 embedding; | ||
| private Lifecycle lifecycle; | ||
|
|
||
| ActivityState( |
There was a problem hiding this comment.
the behavior of ActivityState#release() depends upon which constructor is used.
| } | ||
|
|
||
| @Test | ||
| public void onDetachedFromActivity_ShouldReleaseActivityState() { |
There was a problem hiding this comment.
what about testing ActivityState#release() - Is that covered somehow?
There was a problem hiding this comment.
ActivityState#release() is an internal helper function and does not need to add special test cases. Here we just need to make sure that ActivityState is released as expected after onDetachedFromActivity is called.
670c612 to
b191e9c
Compare
There was a problem hiding this comment.
No version change: The PR does not involve external interface changes.
That's not how our version change policy works. This needs a version change. (I've removed this from the description so that our CI checks will work correctly.)
Please read the explanation of versioning linked from the checklist item about versions.
| * Updates Android compileSdkVersion to 31. | ||
| * Fix iOS RunnerUITests search paths. | ||
| * Fixes iOS RunnerUITests search paths. | ||
| * Fixes Activity leak. |
There was a problem hiding this comment.
Version 0.8.4+5, which is now 5 versions old, did not include this fix.
b191e9c to
833d9ae
Compare
| * Improves the documentation on handling MainActivity being killed by the Android OS. | ||
| * Updates Android compileSdkVersion to 31. | ||
| * Fix iOS RunnerUITests search paths. | ||
| * Fixes iOS RunnerUITests search paths. |
There was a problem hiding this comment.
Please don't change old versions' notes.
| @@ -1,3 +1,7 @@ | |||
| ## NEXT | |||
There was a problem hiding this comment.
As I said before, and as it says in the document I referenced above, this PR needs a version change.
72ff357 to
86a271e
Compare
Fixes flutter/flutter#92148
Pre-launch Checklist
dart format.)[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.