# kotlin-android-extensions

Published articles for kotlin-android-extensions.

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

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

## A study of the Parcelize feature from Kotlin Android Extensions

DevFeed: [A study of the Parcelize feature from Kotlin Android Extensions](<https://devfeed.tech/articles/a-study-of-the-parcelize-feature-from-kotlin-android-extensions-25876.md>)

Original publisher: [Read original article](<https://bladecoder.medium.com/a-study-of-the-parcelize-feature-from-kotlin-android-extensions-59a5adcd5909?source=rss-54910f05af37------2>)

Author: Christophe Beyls

Published: 2019-11-19T07:31:01Z

Content type: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [Android Studio](<https://devfeed.tech/topics/android-studio.md>), [jetbrains](<https://devfeed.tech/topics/jetbrains.md>), [Google](<https://devfeed.tech/topics/google.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [google](<https://devfeed.tech/tags/google.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [gradle-plugin](<https://devfeed.tech/tags/gradle-plugin.md>), [jetbrains](<https://devfeed.tech/tags/jetbrains.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-android](<https://devfeed.tech/tags/kotlin-android.md>), [kotlin-android-extensions](<https://devfeed.tech/tags/kotlin-android-extensions.md>), [parcelable](<https://devfeed.tech/tags/parcelable.md>), [parcelize](<https://devfeed.tech/tags/parcelize.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [production](<https://devfeed.tech/tags/production.md>)

### AI overview

This article examines Kotlin's Parcelize feature, formerly part of Kotlin Android Extensions, as a production-ready way to generate Android Parcelable implementations. It discusses the feature's generated-code efficiency, plugin support, handling of unsupported types, and lack of runtime library overhead, then introduces the required Kotlin and Android Studio setup.

### Source excerpt

Life is too short to waste time on writing Parcelable code Two years ago, I wrote about how you can leverage features of the Kotlin programming language to manually write your Android Parcelable implementations in the most concise and readable way. Does it mean that I always prefer writing this code manually rather than letting a library or tool generate it for me? Of course not: like most developers, I believe that the best code is the code you don't have to write. But I expect the tools I use to meet my quality standards. That's why I tend to be conservative about the dependencies I add to my projects and will always favor official libraries from Jetbrains or Google over third-party solutions. Things have changed for the better since I wrote the previous article: with the release of Kotlin 1.3.40, @Parcelize is now a stable feature provided by the Parcelize Gradle plugin (formerly known as Kotlin Android Extensions). And since version 1.3.60, the Android Studio plugin also properly recognizes the feature as non-experimental so it can finally be considered as production-ready. I previously enumerated a list of some of the negative aspects of third-party Parcelable code generation libraries compared to manual implementation. Here's why I believe @Parcelize stands out from the rest in regard to that list: It's an official plugin made by JetBrains with the collaboration of Google and is guaranteed to be well supported in the future The generated code of @Parcelize is very efficient (as we'll discover further in this article) The CREATOR field doesn't have to be declared at all, along with that easy-to-forget @JvmField annotation Thanks to the Parceler interface, it is possible to write simple plugins to handle unsupported types or override the default implementation No extra classes are created by the plugin. All the generated code is embedded in the annotated class so the app will behave exactly as if you wrote the code yourself There is no runtime library overhead a

## Kotlin Android Extensions: View access, caching, and deprecation

DevFeed: [Kotlin Android Extensions: View access, caching, and deprecation](<https://devfeed.tech/articles/kotlin-android-extensions-say-goodbye-to-findviewbyid-kad-04-27179.md>)

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

Published: 2017-08-16T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [deprecated](<https://devfeed.tech/topics/deprecated.md>), [Code](<https://devfeed.tech/topics/code.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [XML](<https://devfeed.tech/topics/xml.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [cache](<https://devfeed.tech/tags/cache.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-android-extensions](<https://devfeed.tech/tags/kotlin-android-extensions.md>), [xml](<https://devfeed.tech/tags/xml.md>)

### AI overview

This tutorial explains Kotlin Android Extensions for accessing Android views by ID without repeated findViewById calls. It describes generated code, a local view cache, module setup, XML view access, imports, and how to inspect the generated Kotlin bytecode. The article notes that Kotlin Android Extensions are deprecated and recommends View Binding.

### Source excerpt

Everything Android, Kotlin and other random topics

## Kotlin for Android (IV): Custom Views and Android Extensions

DevFeed: [Kotlin for Android (IV): Custom Views and Android Extensions](<https://devfeed.tech/articles/kotlin-for-android-iv-custom-views-and-android-extensions-27176.md>)

Original publisher: [Read original article](<https://antonioleiva.com/kotlin-android-custom-views>)

Published: 2015-05-07T00:00:00Z

Content type: tutorial

Language: en

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

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

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-android-extensions](<https://devfeed.tech/tags/kotlin-android-extensions.md>)

### AI overview

This tutorial explains how Kotlin constructors can support Android custom views and how Kotlin Android Extensions can generate properties for XML views, avoiding explicit findViewById calls. It also briefly mentions Anko for creating Android layouts with Kotlin.

### Source excerpt

Everything Android, Kotlin and other random topics