Skip to content

Instantly share code, notes, and snippets.

@venator85
Created April 30, 2013 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venator85/5487144 to your computer and use it in GitHub Desktop.
Save venator85/5487144 to your computer and use it in GitHub Desktop.
Otto issue
package com.example.provaandroid;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.squareup.otto.Bus;
import com.squareup.otto.Produce;
import com.squareup.otto.Subscribe;
public class MyActivity extends Activity {
public static class Father {
@Override
public String toString() {
return "I am father - " + super.toString();
}
}
public static class Son extends Father {
@Override
public String toString() {
return "I am son - " + super.toString();
}
}
private Bus bus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bus = new Bus();
bus.register(this);
Log.e("MyActivity", "------------");
bus.post(new Son());
// actual output is:
// 04-30 09:14:06.676: E/getFather(1801): got father I am father - com.example.provaandroid.MyActivity$Father@b579d0d8
// 04-30 09:14:06.676: E/getSon(1801): got son I am son - I am father - com.example.provaandroid.MyActivity$Son@b579d740
// 04-30 09:14:06.676: E/MyActivity(1801): ------------
// 04-30 09:14:06.676: E/getFather(1801): got father I am son - I am father - com.example.provaandroid.MyActivity$Son@b579de40
// 04-30 09:14:06.676: E/getSon(1801): got son I am son - I am father - com.example.provaandroid.MyActivity$Son@b579de40
// extected is:
// 04-30 09:14:06.676: E/getFather(1801): got father I am father - com.example.provaandroid.MyActivity$Father@b579d0d8
// 04-30 09:14:06.676: E/getSon(1801): got son I am son - I am father - com.example.provaandroid.MyActivity$Son@b579d740
// 04-30 09:14:06.676: E/MyActivity(1801): ------------
// 04-30 09:14:06.676: E/getSon(1801): got son I am son - I am father - com.example.provaandroid.MyActivity$Son@b579de40
}
@Subscribe
public void getFather(Father father) {
Log.e("getFather", "got father " + father);
}
@Subscribe
public void getSon(Son son) {
Log.e("getSon", "got son " + son);
}
@Override
protected void onDestroy() {
super.onDestroy();
bus.unregister(this);
}
@Produce
public Father produceFather() {
return new Father();
}
@Produce
public Son produceSon() {
return new Son();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment