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

Source: Internet
Author: User

Google Guice on Android (Roboguice)Introducing Google's open-source framework today, Roboguice, is almost the same as the dagger framework that was described earlier, just as 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 roboguice save a lot of time. Fewer of the code means fewer errors. Fewer boilerplate code means that you can put a lot of other time into your application's core logic. So that's why we're using these open source frameworks for development. Here's what we say 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) , 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, very many people feel that roboguice is very inefficient, so very few people are willing to use this, and many others tend to use AA (Android Annotation).
    Of Course there are other annotations in Roboguice:such as:@ContentView (R.layout.layout_main) replaces Setcontentview (r.layout.layout_main);@ContextSingleton to design a singleton class. (In fact, in dagger)suppose netizens are interested. Go deeper into its Java Doc (http://www.imobilebbs.com/download/android/roboguice/javadoc/)

    Butter KnifeThis framework is the same as the use of the Roboguice framework. By the way, record a little bit. Examples:
    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 '

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

    Related Article

    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.