我应该使用 RoboGuice 还是其他依赖注入框架?

Should I Use RoboGuice or other Dependency Injection Frameworks?

我从一个朋友那里听说 RoboGuice. But I found Official document of Android when I was reading this 使 Coading 变得更容易和更简单。在其 第二点 中,作者说:

Official document of Android suggests to avoid dependency injection frameworks like Guice or RoboGuice, reason being is it’s a reflection based library and it creates overheads at run time. Even it tends to perform a lot of process initialization by scanning your code for annotations, which can require significant amounts of your code to be mapped into RAM even though you don’t need it. (Here I would say we can use Android annotation library because it creates duplicate copy of annotated classes so it won’t create any overhead at runtime but at compile time.)

所以我应该使用它还是不使用它?任何帮助将不胜感激。

是的,它变得更容易了,但是正如您在官方文档中阅读的那样,这种依赖注入会降低您的应用程序性能,因为它依赖于 Java's Reflection
但并不是所有的依赖注入都像 Butterknife and Dagger 2 这样使用反射,所以它不会影响你的应用程序性能。

Butterknife 用法示例:

class ButterknifeActivity extends Activity {
  @Bind(R.id.title) TextView title;
  @Bind(R.id.logo) ImageView logo;

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    ButterKnife.bind(this);
  }
}

使用 Butterknife,您无需调用 findViewById 并强制转换它,库会为您完成。