Third-party frameworks used by the AndroidAnnnotations injection framework integrate the Otto event bus (14th)

Source: Internet
Author: User

Third-party frameworks used by the AndroidAnnnotations injection framework integrate the Otto event bus (14th)

 

 

This article is from: [Jiang qingqing's blog]

(1). Preface:

We have already explained how to integrate the AndroidAnnotations framework with RoboGuice. Today we will start to learn more about integrating the third-party framework with the Otto event bus. The Otto event bus is similar to the Eventbus we often use. Otto Official Website: decoupling ).

 

(2). Integration of Otto and AndroidAnnotations

  • Integrate the AndroidAnnotations framework into the project (for details, see [FastDev4Android framework development] AndroidAnnnotations injection framework introduction and basic configurations of Android Studios (7)
  • Integrate the otto framework into the project (for details, please refer to the http://square.github.io/otto/) here to talk about AndroidStudio Configuration:

    Dependencies {

    Compile 'com. squareup: otto: 1.3.8'

    }

    • Use @ EBean to create a singleton class for the event Bus
    • Create an event class for transmission and distribution through the event Bus
    • Use bus. post () to send events to the event bus
    • Use @ Subscribe for annotation to obtain published events

      The following example indicates that the title of the notification Activity is updated by Fragment:

       

      // Declare the busas an enhanced bean@EBean(scope =Scope.Singleton)public class OttoBusextends BasicBus { }public classUpdateTitleEvent {         public final String title;         public UpdateTitleEvent(String title) {                this.title = title;        } }

      @EActivity(R.layout.hello_activity)public classHelloAndroidActivity extends FragmentActivity {         @Bean        OttoBus bus;         @Override        protected void onCreate(BundlesavedInstanceState) {               super.onCreate(savedInstanceState);                bus.register(this);        }         @Override        protected void onDestroy() {                super.onDestroy();                bus.unregister(this);        }     @Subscribe    public void onUpdateTitle(UpdateTitleEventevent) {        setTitle(event.title);    } }

      @EFragment(R.layout.hello_fragment)public classHelloFragment extends Fragment {     int counter = 1;     @Bean    OttoBus bus;     @Click    void fragmentButtonClicked() {        bus.post(newUpdateTitleEvent(Clicks:  + counter++));    }}
      At this point, Otto integration for third-party framework integration of AndroidAnnotations has been fully explained.

       

       

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.