Skip to content

Instantly share code, notes, and snippets.

@DJDarkByte
Last active August 21, 2020 22:50
Show Gist options
  • Select an option

  • Save DJDarkByte/bf6c0f0984faf93ba53788ae349c40ca to your computer and use it in GitHub Desktop.

Select an option

Save DJDarkByte/bf6c0f0984faf93ba53788ae349c40ca to your computer and use it in GitHub Desktop.
RecyclerView that cleans up it's mess instead of leaking
class LifecycleRecyclerView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr), LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
private fun onDestroy() {
adapter = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment