Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
uc...@gmail.com <uc...@gmail.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 918b7b274374a2998b70622de9194f73862b0903
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 10 13:26:19 2020
Add lint for LiveData.observe() extension function
The lint rule to replace the fragment LifecycleOwner with the
viewLifecycleOwner in calls to LiveData.observe works fine, but it misses
cases that use the LiveData.observe extension function.
This changes adds the extension function to the list of lint rules.
Test: Verified in sample app
Bug: 148996309
Change-Id: I05d1fe78d088b0d6cce5aa79454b98d25c50faef
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
https://android-review.googlesource.com/1231871
Branch: androidx-master-dev
commit 918b7b274374a2998b70622de9194f73862b0903
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 10 13:26:19 2020
Add lint for LiveData.observe() extension function
The lint rule to replace the fragment LifecycleOwner with the
viewLifecycleOwner in calls to LiveData.observe works fine, but it misses
cases that use the LiveData.observe extension function.
This changes adds the extension function to the list of lint rules.
Test: Verified in sample app
Bug: 148996309
Change-Id: I05d1fe78d088b0d6cce5aa79454b98d25c50faef
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
an...@google.com <an...@google.com> #6
jb...@google.com <jb...@google.com> #7
This has been fixed internally and will be available in the Fragment 1.2.2 release.
Description
Version used:
androidx.fragment:fragment:1.2.0
androidx.lifecycle:lifecycle-lifedata:2.2.0
Devices/Android versions reproduced on: Android studio lint issue. (Android Studio 4.0 canary 9)
I like your lint detector and I agree UnsafeFragmentLifecycleObserverDetector's direction.
UNSAFE_METHODS is like that.
internal val UNSAFE_METHODS = mapOf(
Method("androidx.lifecycle.LiveData", "observe") to LIVEDATA_ISSUE,
Method("androidx.activity.OnBackPressedDispatcher", "addCallback") to BACK_PRESSED_ISSUE
)
(SourceCode referenced is :
And 'inline fun <T> LiveData<T>.observe' was add in 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0'.
It isn't catch by lint in "onCreateView", "onViewCreated", "onActivityCreated", "onViewStateRestored". When I used viewModel.liveData.observe(this) { } in Fragment.
So I hope to add one unsafe method in map of 'UNSAFE_METHODS'.
Method("androidx.lifecycle.LiveDataKt", "observe") to LIVEDATA_ISSUE,
I was test in my example and works good.
Let me know your opinion.
Best Regards.
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).