An Introduction to
Posted by Ed George
There’s one exciting feature coming out of Android’s big bag of tricks that has a lot of mobile developers buzzing. I’m talking about the new ‘data binding’ library that’s just entered a beta release in Gradle (version 1.3.0-beta4); this will most likely be featured heavily in the upcoming Android Marshmallow release later this year.
So what is it and what can it do?
The data-binding library has been created by Google to help eliminate some of the ‘spaghetti’ boilerplate code that plagues the majority of applications when their views and layouts are created.
For developers this is a miracle as, simply put, the library can now let the simple naming of a variable be enough for Android to make the link between the layout component and a variable itself. Previously, this required a line of code (or more) for each element a developer wished to access directly; the new Data Binding library can now complete this same action using only one line of code.
One of the most interesting additions to this library is that it allows layout files to also handle logic and variables after being bound. These variables and logic can be defined directly within the actual layout code, and means layouts can be ‘dynamic’ while showing information without having to define behaviours within the application code.
One good example of this is a simple profile page that contains basic information on a user such as name, age, date of birth, etc. Pre-data binding a layout and its’ elements would have to be populated from a user record with the relevant information one-by-one programmatically. However, it’s now possible to reference the user variable within the layout and then, through binding, populate these fields automatically. Saving time, and subsequently, making development of non-complicated layouts an easy-breeze for developers.
The more advanced developers may also be interested in the new ‘Null Coalescing Operator’, styled as two question marks (??), that’s supported in layouts that utilise this new Data Binding library. It’s essentially short code for a ternary operator null check and simply chooses the left operand if it’s not null or the right otherwise.
What does this mean for me, as an Android developer?
Nothing on the surface of the app will change from a users’ perspective, as an app using this library will function exactly the same as one using the now archaic method of populating layouts.
What should be changing is the length of time developers require to create layouts. This means development can be completed quicker, and complex layouts should become far less tedious to create and work with. This in turn gives designers more free reign on their designs, allowing more creative designs to become feasible as the functionality of this library increases.
No word has been given yet by Google on exactly when the library will go from its beta stage into a full release; but here at Hi Mum! Said Dad, we’re always investigating these new tools and how they’ll affect, and better, our development process. The Data Binding Library is something we’re very excited about and something we’ll be fully embracing in the near future. Less code + better products in less time = everyone wins.
Want to know more about Android’s new Data Binding Library and how it can help your business? Please get in touch, we’d love to hear from you!
Read more on Android’s new Data Binding Library here:
Originally published at www.himumsaiddad.com.