Cody Engel
04/16/2020, 5:15 PMTypedArray
in Android, I added the following extension function to handling parsing the values:
fun TypedArray.parseStyledAttributes(parse: (typedArray: TypedArray) -> Unit) {
try {
parse(this)
} finally {
recycle()
}
}
However the call-site still gives a lint warning "This typed array should be recycled after use with #recycle()". Is there anything I could do besides adding @SuppressLint("Recycle")
everywhere?@SuppressLint("Recycle")
fun Context.parseStyledAttributes(
attributeSet: AttributeSet?,
attributes: IntArray,
parser: (typedArray: TypedArray) -> Unit
) {
obtainStyledAttributes(attributeSet, attributes).parseStyledAttributes(parser)
}
Alex Vanyo
04/16/2020, 5:33 PMTypedArray.use
extensionCody Engel
04/16/2020, 5:59 PMuse
doesn't appear to remove the lint warning.jw
04/16/2020, 6:09 PMCody Engel
04/16/2020, 6:13 PMContext
has withStyledAttributes
which calls recycle as a part of core ktx. I'm just going to stop trying to reinvent extension functions that already exist 🤦🏻Alex Vanyo
04/16/2020, 7:09 PM"Recycle"
warning in the past, but those seem to have been resolved recently with Android Studio 4.0 and the 4.0.0 Gradle plugin.
Maybe it was fixed from this?
https://issuetracker.google.com/issues/140344435Cody Engel
04/16/2020, 7:23 PM