Android Roboguice Open source framework, Butter Knife Open source Framework analysis

Source: Internet
Author: User

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 '  

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.