Google Guice on Android (Roboguice)today, Google's open-source framework Roboguice, its role is almost the same as the previous dagger framework, but Dagger is more powerful than its function. Dagger achieves better performance in a different way by focusing on a simplified set of features. Some people think that roboguice save a lot of time. Less code means fewer errors, and less boilerplate code means more time can be put into the core logic of the application. So that's why we're using these open source frameworks for development. Let's talk about the use of Roboguice:
views Injection: @InjectView (r.id.textview1) TextView textView1;//So we get this TextView object entity , &NB Sp
resources injection:   getresources (). getdrawable (R.id.ic_launcher) This way , instead of using @InjectResources annotations, such as: @ Injectresource (r.id.ic_launcher) drawable iclauncher ; , &NB Sp , &NB Sp
System Services Injection: get some system-level service objects and no longer follow the original
Locmanager = (locationmanager) getsystemservice (Activity.location_service), the method is implemented using @inject annotations, such as:
@Inject locationmanager Locmanager;
POJO Object injection: injecting A simple Java object (POJO) is also @inject with annotations, such as: @Inject Student Student;
in fact, many people think that roboguice is inefficient, so few people are willing to use this, and more people tend to use AA (Android Annotation).
There are , of course, some other annotations in Roboguice:such as:@ContentView (r.layout.layout_main) instead of Setcontentview (R.layout.layout_main);@ContextSingleton to design a singleton class. (In fact, in dagger)if the netizen is interested, then go in-depth study its Java DOC (http://www.imobilebbs.com/download/android/roboguice/javadoc/)
Butter KnifeThis framework is the same as the use of the Roboguice framework, incidentally, with a little bit of a record. Example:
class exampleactivity extends Activity { @InjectView(R.ID.User) EditText username; @InjectView(R.ID.Pass) EditText Password; @OnClick(R.ID.Submit) void Submit() { //TODO call Server ... } @Override Public void onCreate(Bundle savedinstancestate) { Super.onCreate(savedinstancestate); Setcontentview(R.Layout.simple_activity); Butterknife.Inject( This); //TODO use ' injected ' views ... }}
configuration in Gradle:
compile ' com.jakewharton:butterknife:5.1.1 '