Does “Avoid dependency injection frameworks” in the Android Memory Guide apply to Dagger as well?

后端 未结 4 1431
Happy的楠姐
Happy的楠姐 2020-12-08 09:10

So I have come across this best practices on Android articles on memory performance.

http://developer.android.com/training/articles/memory.html

They said

4条回答
  •  有刺的猬
    2020-12-08 10:05

    The creator of Dagger, @JakeWharton, also wrote a simpler view "injection" framework called Butterknife

    because all the RoboGuice converts were complaining about lack of "view injection" with Dagger.

    You use it like this:

    class ExampleActivity extends Activity {
      @InjectView(R.id.title) TextView title;
      @InjectView(R.id.subtitle) TextView subtitle;
      @InjectView(R.id.footer) TextView footer;
    
      @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_activity);
        ButterKnife.inject(this);
        // TODO Use "injected" views...
      }
    }
    

提交回复
热议问题