https://kotlinlang.org logo
#android
Title
# android
l

leosan

09/21/2018, 9:15 AM
I was looking into plaid source and they have this delegate for databinding https://github.com/nickbutcher/plaid/blob/757ee036c4eed46431982c1de5e6d0b57809fea2/core/src/main/java/io/plaidapp/core/util/delegates/ContentViewBindingDelegate.kt I’ve created mine like this, is there any performance or big difference between the two?
Copy code
inline fun <reified T : ViewDataBinding> FragmentActivity.contentView(@LayoutRes layoutRes: Int) = lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
    DataBindingUtil.setContentView<T>(this, layoutRes)
}
k

kingsley

09/22/2018, 10:48 AM
You probably should use
LazyThreadSafetyMode.NONE
, since this will always run on the UI thread anyway Using
SYNCHRONIZED
might be a little less performant due to extra (unnecessary) concurrency synchronization mechanism
👍 1
3 Views