‫Hello my friends, and welcome back.
‫In this video we'll learn about Android data binding library we used before the Findviewbyid method.
‫In all of our applications.
‫This method will find the first descendant view with the given ID.
‫Every time we use Findviewbyid method.
‫To get the reference to the view, Android system must go through the view hierarchy and find it at
‫runtime.
‫The first issue is what about large applications with hundreds of views and layouts?
‫Modern mobiles nowadays have a refresh rate 60Hz per one second, so Android system will create our
‫layout with all its views every 16.667 milliseconds for a refresh rate 60Hz.
‫The second issue.
‫What about mobiles with 90Hz, 120Hz, 144Hz and more?
‫So Android system will create our layout with all its views with less time, and this could lead to
‫memory leaks and missing views.
‫The solution is to use the data binding library.
‫Android jetpack is a set of libraries designed to help developers follow best practices and create code
‫quickly and simply.
‫The data binding library is one of these libraries, so the data binding library is a support library
‫that allows you to bind UI components in your layout to data sources in your app, using a declarative
‫format rather than programmatically.
‫Data binding is the process of integrating views in an XML layout with data objects.
‫The data binding library is responsible for generating the classes required for this procedure, using
‫data binding and binding object will be created.
‫This is the step how the data binding library works.
‫Using the data binding, a binding object will be created that contains a reference to each view of
‫a layout.
‫So the Android system will not go and search the views by their IDs again and again.
‫It will go to this data binding object and get the reference to each view of the layout.
‫Data binding is the process of integrating views in an XML layout with data objects.
‫The data binding library is responsible for generating the classes required for this procedure.
‫Why we use the data binding in our application.
‫You can reduce findviewbyid calls and enhance your app's performance.
‫Helps get rid of memory leaks or null pointer exceptions.
‫Uses a declarative layout which is more adaptable.
‫Supercharges developer productivity by writing error free, shorter, simpler to understand, and more
‫maintainable code.
‫Data and views are separated from each other.
‫The compiler verifies types during compile time and displays errors when you attempt to assign the incorrect
‫type to a variable, thanks to type.
‫Safety.
‫In most cases, the default class name corresponds to the name of the layout file followed by the binding
‫post-fix.
‫For example, if we have the main activity dot XML file or activity underscore main dot XML file.
‫This is the name of the layout for the main activity.
‫Using that Android data binding library will create a binding object with the name of activity capital
‫A.
‫We remove the underscore main with m capital and the binding post-fix so when you see binding keyword
‫in the object naming, this will refer for the data binding library.
‫So if you use layout tag in the activity underscore main layout, the data binding library will create
‫a binding object with the name called activity main binding.
‫Let's jump into Android Studio and learn about data binding with a quick example.