# view-binding

Published articles for view-binding.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## 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: [Stories by Kirill Rozov on Medium](<https://devfeed.tech/sources/stories-by-kirill-rozov-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Library](<https://devfeed.tech/topics/library.md>), [Jetpack](<https://devfeed.tech/topics/jetpack.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.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>), [fragments](<https://devfeed.tech/tags/fragments.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [library](<https://devfeed.tech/tags/library.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [performance](<https://devfeed.tech/tags/performance.md>), [recyclerview](<https://devfeed.tech/tags/recyclerview.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [release](<https://devfeed.tech/tags/release.md>), [ui](<https://devfeed.tech/tags/ui.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

### AI overview

This article announces ViewBindingPropertyDelegate 2.0, a release that refactors how the Android library manages ViewBinding lifecycles. It replaces Jetpack Lifecycle-based detection with component lifecycle callbacks for Fragments and Activities, improving the timing of reference clearing and addressing issues related to Fragment animations. The release also supports lazy ViewBinding creation and aims to prevent memory leaks.

### 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

## Lessons Learned with Jetpack Compose

DevFeed: [Lessons Learned with Jetpack Compose](<https://devfeed.tech/articles/lessons-learned-with-jetpack-compose-23972.md>)

Original publisher: [Read original article](<https://medium.com/making-meetup/lessons-learned-with-jetpack-compose-29ab74387fc?source=rss----6981e268ba45---4>)

Author: Joe Williams

Published: 2023-05-12T15:44:18Z

Content type: tutorial

Language: en

Sources: [Making Meetup - Medium](<https://devfeed.tech/sources/making-meetup-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Android](<https://devfeed.tech/topics/android.md>), [XML](<https://devfeed.tech/topics/xml.md>), [Android Studio](<https://devfeed.tech/topics/android-studio.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [compose-ui](<https://devfeed.tech/tags/compose-ui.md>), [declarative](<https://devfeed.tech/tags/declarative.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [meetup](<https://devfeed.tech/tags/meetup.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

### AI overview

This developer article shares Meetup's experience adopting Jetpack Compose alongside SwiftUI and integrating Compose into an existing Android app. It explains the benefits of declarative UI, including faster UI development and simpler component reuse, while discussing the transition from XML layouts and view binding. It also covers Compose previews, Live Edit, and ComposeView and AndroidView for integration with traditional layouts.

### Source excerpt

Photo by Brett Jordan on Unsplash At Meetup, we are all-in on declarative UI. Our Organizer app was built from the ground up with Jetpack Compose and SwiftUI. We like it so much we've been integrating it into our existing Meetup app whenever possible. That road has not always been a smooth one, though, and we'd like to share some of what we've learned on that journey. Making the switch is worth it No doubt, some developers are hesitant to pick up yet another newly emerging Android technology. I certainly was. It's tempting to stay in the comfort of XML layouts and view binding. But wouldn't it be nice to create a screen with just one file? Do you really want to keep filling in boilerplate code for RecyclerViews and Adapters? We found that once everyone is on the same page with Compose, UI development speeds up significantly. Reusing a UI component is now just a matter of writing the declaration for it. No more extending a view, dropping it into an XML file, and then hooking up the backing code. Set up previews and use Live Edit When switching from XML layouts to Compose, the first downside that may jump out at developers is one of previewing the UI. For standard XML, changes made are reflected immediately in the design view, while Compose requires the app to be built. There are two things that can help alleviate this problem: Previews and the Live Edit feature. Declaring previews allows you to see how your composables will look in a running app. This is especially useful for commonly used elements. For instance, we have a MeetupButton that gets used across both of our apps, so having previews of each version of it helps us quickly identify which one to use when we're building a screen. Previews also make it easy to test layouts without repeatedly running your application and simulating states: Alongside previews, Live Edit lets you make changes to your composables while the app is running and see those changes immediately. Simply deploy your app from Android Studio

## ViewLifecycleLazy and other ways to avoid View memory leaks in Android Fragments

DevFeed: [ViewLifecycleLazy and other ways to avoid View memory leaks in Android Fragments](<https://devfeed.tech/articles/viewlifecyclelazy-and-other-ways-to-avoid-view-memory-leaks-in-android-fragments-25885.md>)

Original publisher: [Read original article](<https://bladecoder.medium.com/viewlifecyclelazy-and-other-ways-to-avoid-view-memory-leaks-in-android-fragments-4aa982e6e579?source=rss-54910f05af37------2>)

Author: Christophe Beyls

Published: 2022-09-28T06:12:25Z

Content type: tutorial

Language: en

Sources: [Stories by Christophe Beyls on Medium](<https://devfeed.tech/sources/stories-by-christophe-beyls-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [architecture-components](<https://devfeed.tech/tags/architecture-components.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

### AI overview

This article presents ViewLifecycleLazy, a Kotlin delegated property for Android Fragments that lazily initializes values tied to the current Fragment view lifecycle and clears them when the view hierarchy reaches the DESTROYED state. It explains how this approach helps prevent view-related memory leaks and compares it with AutoClearedValue and manual clearing in onDestroyView().

### Source excerpt

Yet another take on AutoClearedValueAre your Fragments leaking? Handling the lifecycle of Android Fragments is difficult. I already covered this topic in an article I wrote in 2017, before Google added a View-specific Lifecycle to Fragments in an attempt to solve some issues. Until now, the number one cause of memory leaks when using Fragments remains the same: not properly clearing all direct and indirect View references in onDestroyView(). Tools like Leak Canary can help detecting some of these cases. And of course, Jetpack Compose represents a big paradigm change which completely removes the need to keep View references but hey, we still have our legacy codebases to maintain! I recently came across a Medium blog post from Gabor Varadi describing an issue he encountered with a custom Kotlin delegated property he created to simplify managing view bindings in Fragments. His solution is based on a class named AutoClearedValue from the architecture components samples. The purpose of AutoClearedValue is to provide a delegate that will automatically clear a value tied to one or more Views when the Fragment View hierarchy gets destroyed, in order to avoid the aforementioned memory leaks. This is an elegant alternative to declaring a Fragment property as nullable and manually setting it to null in onDestroyView(), which can be easily forgotten. It turns out I had already come up with my own solution to do the exact same thing. And since my version is simpler and generates more optimized bytecode compared to AutoClearedValue and what Mr Varadi published, I decided to share it with you. I named this delegate ViewLifecycleLazy. Like the name implies, the delegated property value is computed lazily and the Fragment's current view lifecycle is observed in order to automatically clear the value when it moves to the DESTROYED state. https://medium.com/media/17c61e41a0f2d3e17c63e3bcf8f6376c/href This is how it's used in Fragments, for example with View Binding: class MyFragment :

## Fragments, ViewBinding and memory leaks

DevFeed: [Fragments, ViewBinding and memory leaks](<https://devfeed.tech/articles/fragments-viewbinding-and-memory-leaks-25871.md>)

Original publisher: [Read original article](<http://lordraydenmk.github.io//2020/view-binding/>)

Author: Stojan Anastasov

Published: 2020-10-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [Stojan Anastasov's blog](<https://devfeed.tech/sources/stojan-anastasov-s-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-android-extensions](<https://devfeed.tech/tags/kotlin-android-extensions.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

### AI overview

This article explains how Android view binding works with Kotlin and Java, focusing on the risk of memory leaks when a Fragment retains a binding after its view is destroyed. It argues that the issue results from placing the binding reference in the Fragment scope and recommends keeping it in a shorter-lived local function scope, particularly when using MVVM.

### Source excerpt

As an Android engineer one of the basic things you need to do is bind the views (written in XML) with Kotlin/Java code. You can do this with the basic primitive -findViewById(), using a library like ButterKnife, using a compiler plugin like Kotlin Android Extensions or starting with Android Studio/AGP 3.6 ViewBinding. There are a few other options out there but in my experience these are the most common. The Kotlin Android Extensions plugin will be deprecated (except the @Parcelize functionality) in favor of ViewBinding soon. I see this as a positive change, but not everyone shares my opinion. One of the common arguments against ViewBinding (according to a comment in the ticket, a discussion on reddit and a friend of mine) is: ViewBinding introduces memory leaks in Fragments. Let's take a look into the usage example from the official docs: private var _binding: ResultProfileBinding? = null // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { _binding = ResultProfileBinding.inflate(inflater, container, false) val view = binding.root return view } override fun onDestroyView() { super.onDestroyView() _binding = null } The fragment outlives the view, which means that if we forget to clear the binding reference in onDestroyView this will cause a memory leak. Now I do agree that this is error prone, you have to remember to clear the binding reference in each fragment you create. However this problem is not inherent to ViewBinding, but to this kind of usage. The problem here is: a component with a larger scope (the fragment) keeps a reference to a component with a smaller scope (the binding). Clearing the reference is a workaround, the proper solution is to move the reference to the correct scope: private val viewModel by viewModels<ProfileViewModel>() override fun onViewCreated(view: View, savedInsta

## Using View Binding to Access Android XML Views

DevFeed: [Using View Binding to Access Android XML Views](<https://devfeed.tech/articles/view-binding-the-definitive-way-to-access-views-on-android-27233.md>)

Original publisher: [Read original article](<https://antonioleiva.com/view-binding-android>)

Published: 2020-05-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [android-development](<https://devfeed.tech/topics/android-development.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [XML](<https://devfeed.tech/topics/xml.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>), [xml](<https://devfeed.tech/tags/xml.md>)

### AI overview

This tutorial explains Android View Binding, compares it with Data Binding and earlier view-access approaches, and outlines configuration and use in activities and adapters.

### Source excerpt

Everything Android, Kotlin and other random topics

## Replacing Custom Views with View Binding

DevFeed: [Replacing Custom Views with View Binding](<https://devfeed.tech/articles/replacing-custom-views-with-view-binding-25976.md>)

Original publisher: [Read original article](<https://proandroiddev.com/replacing-custom-views-with-view-binding-7836c34185fb?source=rss-8efc0359e234------2>)

Author: Jossi Wolf

Published: 2020-04-19T12:31:58Z

Content type: tutorial

Language: en

Sources: [Stories by Jossi Wolf on Medium](<https://devfeed.tech/sources/stories-by-jossi-wolf-on-medium.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [XML](<https://devfeed.tech/topics/xml.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [code](<https://devfeed.tech/tags/code.md>), [custom-view-android](<https://devfeed.tech/tags/custom-view-android.md>), [dockerignore-usage](<https://devfeed.tech/tags/dockerignore-usage.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>), [xml](<https://devfeed.tech/tags/xml.md>)

### AI overview

This tutorial explains how a codebase replaced reusable custom views with Android View Binding when custom rendering was unnecessary. It covers generated binding objects, lifecycle-scoped instantiation, reusable binding extension functions, and passing data models to reusable components.

### Source excerpt

How we used View Binding to replace Custom Views In our codebase, we use a lot of custom views for reusability -- but most of the time, a custom view was overkill. Here's how we used View Binding to replace some of our custom views. View Binding 101 If you are not familiar with View Binding yet, here is a great post by Sean McQuillan about it. In short: View Binding is a better alternative over Kotlin Synthetics, findViewById and good old Butterknife. It allows you to access the views in a layout in a type-safe and null-safe way. For each XML layout, View Binding generates a binding object. For a layout fragment_login.xml, you'd get a binding object called FragmentLoginBinding. Instantiating the binding objects requires a bit of boilerplate to make sure it is scoped to the components' lifecycle. We use a delegate class as suggested in this post to make the code cleaner and easier to read. About Our Custom Views We used many custom views for our reusable components. Like this one: https://medium.com/media/0d681c4bb6b7d1f682a84aa2e58801ba/href Custom views are awesome if they are used right, but they bring quite a bit of boilerplate and are harder to maintain then XML layouts. For cases where we don't do any custom rendering, View Binding made more sense to use as we could cut down on the boilerplate. Using View Binding for Reusable Components As View Binding generates a binding object for each layout, the first step for migrating was to create a layout: https://medium.com/media/b9c9bf94e38e1b30923d741f6e85d7c4/hrefPreview of the layout Now for our card_user_data.xml, View Binding generates a CardUserDataBinding.java which we can use. Binding the data First, we need to include the card layout in our fragment's layout. https://medium.com/media/1af56e360407fe6f1eaef366f18e6401/href View Binding will automatically cast the type of the <include> to CardUserDataBinding, so we can use it in a type-safe way. That also means we can reuse those bindings across layouts. Beware t