Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • irdest irdest
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 27
    • Issues 27
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • we
  • irdestirdest
  • Merge requests
  • !41

Migration to ViewBinding

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Ghost User requested to merge android/#22-entirely-use-viewbinding into develop Aug 11, 2021
  • Overview 0
  • Commits 5
  • Pipelines 2
  • Changes 30

Issue Fix

Fixes #22 (closed)

Description

Too sleeepy to write it right now 💤

  • ViewBinding over Kotlin Synthetics and findViewById().
  • Doing so is a better way of referencing and using the views, while using Kotlin Synthetics we can get a runtime error in the application resulting in crash. That RTE may arise because of two different views having same Id(which is very possible) in two totally different layouts, also since these Kotlin Synthetics don't come with compile time checks, therefore runtime error is inevitable in the cases like the one mentioned.
  • findViewById() has been removed because it increases memory consumption by the application, as it searches the entire view heirarchy of the layout visible on the screen, in the runtime. Although it does not show that noticeable lag in the application initially, but it becomes a big pita as the application grows.
  • ViewBinding removes all these concerns and generates java classes corresponding to the layout files and uses them for referencing the views, so here do not exist any conflicting declarations like for the case mentioned above for Kotlin Synthetics, because each view is referenced to its corresponding binding class, which is auto-generated from the layout file. Also no runtime errors, as everything gets checked in the compile-time itself. yeah those errors are inevitable if you don't inflate a layout in the application screen and reference them :P

  • TL;DR Kotlin Synthetics have been deprecated(since they cause RTEs) and using findViewById() is a crime

Alternative(s) considered

  • Introduction of ViewBinding
  • Removal of findViewById()
  • Removal of Kotlin Android Extensions aka Kotlin Synthetic Bindings

Type

Choose one: Code health

Screenshots (if applicable)

NA

PS: This branch is based off s-ayush2903/android/#23-KotlinDSL-instead-Groovy so that it doesn't have to face merge conflicts and no need to rebase again after the related MR(!36 (closed)) is merged.

Edited Aug 14, 2021 by Ghost User
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: android/#22-entirely-use-viewbinding