Kay-Uwe Janssen edited this page Oct 9, 2016 · 21 revisions

Since AndroidAnnotations 3.0

Integrating Otto and AndroidAnnotations

  1. Add AndroidAnnotations to your project.
  2. Add the otto AA plugin to your project
  3. Add otto to your project.
  4. Create a singleton class for the bus that can be injected with AA using the @EBean annotation.
  5. Create the event class that will transit through the bus.
  6. Post a new event to the bus: ...)
  7. Use @Subscribe annotation to get the published events.

The following code (taken from the CleanAndroidCode) shows you how an Activity notifies its Fragment that the title has been updated.

// Declare the bus as an enhanced bean
@EBean(scope = Scope.Singleton)
public class OttoBus extends BasicBus {

public class UpdateTitleEvent {

        public final String title;

        public UpdateTitleEvent(String title) {
                this.title = title;

public class HelloAndroidActivity extends FragmentActivity {

        OttoBus bus;

        protected void onCreate(Bundle savedInstanceState) {

        protected void onDestroy() {

	public void onUpdateTitle(UpdateTitleEvent event) {

public class HelloFragment extends Fragment {

	int counter = 1;

	OttoBus bus;

	void fragmentButtonClicked() { UpdateTitleEvent("Clicks: " + counter++));

The @Subscribe and @Produceannotations can be used in any enhanced component.

14/10/2018 The 4.5.1 release is out !

Using AndroidAnnotations


Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.