Data-binding Pros and Cons, Choose wisely

android

I have used data-binding in two projects, I would say data-binding is too bad for your project, it can be the cause of spaghetti code. Let’s see the pros and cons of data-binding.

Pros

1- Easy to use
2- Less boilerplate code (eliminating findViewById and more)
3- Fit to MVVM pattern
4- Synchronize data between sources and UI elements

Cons

1- Showing unrelated errors

Showing unrelated errors when compiler can’t compile the project for any problem, (e.g. Dagger2 or Room or Realm) so compiler can’t generate data-binding related classes so it will show unrelated errors like below:
data-binding_unrelated_errors

2- Business logic belongs in code

It can be more complex if you have different layouts for different screens.

3- Updating view after changing data can be cause of blink

4- Auto-rename for package names doesn’t work on XML files

5- The auto-generated .class files increases app size

it will matter if you have tons of it.

Other Solutions

  • Use databinding but do not use events !! (It can fix the cons #2)
  • Using ButterKnife
  • Using traditional way, findViewById()
  • Using Kotlin Android Extensions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s