Can anyone point out the difference between Dagger and Butterknife? I know that Butterknife is a view injection library and Dagger is a dependency injection library. But the documentation online seems a bit overhead for me. According to Butterknife documentation, you can do non-activity injections as well, which is what Dagger does? Or did I misunderstand something?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
@JakeWharton's answers it partially in the comment:
TL;DR: They complement each other. Use Butterknife for injecting views, Dagger for the rest.
ButterKnife is targeted to inject views only. Non-activity injection just means that you can provide your own view root to inject views from (like with manually inflated views, etc.). Dagger is a bit more complicated. It can inject anything you want as long as you specified
Module
- class which satisfies those dependencies (alternatively you can use constructor injection).As a bottom line - I would say ButterKnife helps you to avoid all that boilerplate code for creating views (aka
(TextView)findViewById(R.id.some_text_view);
. Nothing more. Under the hood it still does all that boring code. So it is not really an injection..Also it worth mentioning that Jake Wharton is one of the developers for both those cool libs :)
Here is some useful links:
Dagger sample project on GitHub
Dagger presentation on Devoxx (Jake Wharton)
Dagger hangout with Dagger devs
Don't have much of useful ButterKnife links. It really simple and straight forward though, so hopefully you don't need any
The difference is pretty straightforward: A butter knife is like a dagger only infinitely less sharp.
As it is pointed out in the documentation.
Here is a link to the Buterknife documentation. It's very straightforward. However, what the documentation doesn't say but the design of Butter Knife implies is that you can also use Butter Knife in custom views. Just replace "this" with "context" or "getContext" so you determine the scope.
Link: http://jakewharton.github.io/butterknife/
I combine Butter Knife, parcelable and easyAdapter for list views in my project. Reason is less boilerplate and with parcelable faster and cleaner parceling. So if you have a lot of ListViews, I recommend this approach.
Links:
https://github.com/johncarl81/parceler
https://github.com/ribot/easy-adapter
ButterKnife was made to simplify registering click listeners, and to reduce the boilerplate provided by
findViewById()
calls.Dagger and Dagger2 are general purpose dependency injection systems.
Ignore the text on Guice and MVVM, and read
Dependency Injection
andThe Android Way
. This pretty much answers what Dagger is meant to do and simplify.https://spring.io/blog/2011/08/26/clean-code-in-android-applications