# Simplify ViewBinding in Android with ViewBindingPropertyDelegate 2.0

DevFeed: [Simplify ViewBinding in Android with ViewBindingPropertyDelegate 2.0](<https://devfeed.tech/articles/simplify-viewbinding-in-android-with-viewbindingpropertydelegate-2-0-25960.md>)

Original publisher: [Read original article](<https://kirillr.medium.com/whats-new-in-vbpd-2-0-a83565134cff?source=rss-7a0a233f88a2------2>)

Author: Kirill Rozov

Published: 2025-02-04T13:30:45Z

Content type: release

Language: en

Sources: [Kirill Rozov](<https://devfeed.tech/sources/stories-by-kirill-rozov-on-medium.md>)

Topics: [Jetpack](<https://devfeed.tech/topics/jetpack.md>), [recyclerview](<https://devfeed.tech/topics/recyclerview.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-jetpack](<https://devfeed.tech/tags/android-jetpack.md>), [animations](<https://devfeed.tech/tags/animations.md>), [apis](<https://devfeed.tech/tags/apis.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [performance](<https://devfeed.tech/tags/performance.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [release](<https://devfeed.tech/tags/release.md>), [state](<https://devfeed.tech/tags/state.md>), [timing](<https://devfeed.tech/tags/timing.md>), [ui](<https://devfeed.tech/tags/ui.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

## AI overview

ViewBindingPropertyDelegate (VBPD) 2.0 changes how it tracks view destruction: Fragments use FragmentManager.FragmentLifecycleCallbacks, replacing the earlier Lifecycle approach that could clear bindings before onDestroyView() and required a Handler to postpone cleanup. Activities now use ActivityLifecycleCallbacks; ViewGroups remain tied to the ViewGroup instance in memory. The article says these changes improve lifecycle timing, address issues involving Fragment animations, and remove APIs previously needed because of Fragment Lifecycle behavior. VBPD still creates bindings lazily and clears references, and supports Activities, Fragments, ViewGroups, and RecyclerView.ViewHolders. Version 2.0 also removes checks on access timing and thread, leaving errors to the component behavior. Migration requires replacing the old package prefix with dev.androidbroadcast.vbpd and adding dev.androidbroadcast.vbpd:vbpd:2.X.Y; the changed artifact and package names allow old and new versions to coexist.

## Source excerpt

I'm excited to announce the release of ViewBindingPropertyDelegate 2.0, which introduces significant under-the-hood refactoring to enhance the library's stability and performance. In this article, I'll highlight the most important changes and explain how they improve the library's functionality. Brief Introduction ViewBindingPropertyDelegate(VBPD) is a lightweight library designed to simplify the use of Android's ViewBinding by: Managing the ViewBinding lifecycle and clearing references to prevent memory leaks. Eliminating the need to maintain nullable references to Views or ViewBindings. Creating ViewBindings lazily. The library supports usage in various components, including Activities, Fragments, ViewGroups, and RecyclerView.ViewHolders. class ProfileFragment : Fragment(R.layout.profile) { private val profileBinding: ProfileBinding by viewBinding(ProfileBinding::bind) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) // ProfileBinding instance will be created lazily on first access profileBinding.name.text = ... } override fun onDestroyView() { super.onDestroyView() // profileBinding reference will be cleared after onDestroyView() } }Changes in 2.0Transition from Lifecycle to Component Callbacks In previous versions (1.x), VBPD relied on Jetpack's Lifecycle to detect when a View was being destroyed. This approach had a limitation: the Lifecycle callback methods could be invoked before Fragment.onDestroyView(), while the ViewBinding reference was still needed. To address this, VBPD postponed clearing the ViewBinding reference using an Android Handler after onDestroyView(), when the Fragment's View LifecycleOwner transitioned to the DESTROYED state. In version 2.0, VBPD now utilizes FragmentManager.FragmentLifecycleCallbacks to detect when a Fragment's view is destroyed. The key difference lies in the timing of these callbacks, allowing for more precise management of the ViewBinding lifecycle. // Sou