I am using Otto 1.3.3 and when I resume my application sometimes I get an IllegalArgumentException
with the following stacktrace:
Caused by: java.lang.IllegalArgumentException: Producer method for type class
com.couchsurfing.mobile.ui.setup
.SessionProviderFragment$SessionConnectionStateChangeEvent found on
type class com.couchsurfing.mobile.ui.setup.SessionProviderFragment,
but already registered by type class
com.couchsurfing.mobile.ui.setup.SessionProviderFragment.
at com.squareup.otto.Bus.register(Bus.java:194)
at com.couchsurfing.mobile.ui.BaseRetainedFragment
.onCreate(BaseRetainedFragment.java:20)
The SessionProviderFragment
has its instance retained, please find below the extended class:
public abstract class BaseRetainedFragment extends SherlockFragment {
@Inject
Bus bus;
@Override
public void onCreate(final Bundle state) {
super.onCreate(state);
((CouchsurfingApplication) getActivity().getApplication()).inject(this);
setRetainInstance(true);
bus.register(this);
}
@Override
public void onDestroy() {
super.onDestroy();
bus.unregister(this);
bus = null;
}
}
I tried both using bus.register(this)
in onAttach()
or onCreate()
, that didn't change the issue.