IllegalArgumentException in OTTO when unregistering a fragment
I am using Otto bus to pass events from activity to fragments. The problem is that fragments are manageable ViewPager
and the fragment can be recreated without executing it onPause()
and / or onResume()
. An unpleasant side effect is that when bus.unregister(fragment)
called in onPause()
, the call is intermittently interrupted with an IllegalArgumentException. I also suspect that calls to my annotated method @Subscribe
might be skipped as the call bus.register()
is in onResume()
, which cannot be called either. And unfortunately there is no method bus.isRegistered(fragment)
for safe verification.
Is there a better way to register / unregister a managed ViewPager fragment?
I am aware of this post that discusses a similar setup but does not include snippets running in the ViewPager
source to share
If you came here because you have a similar problem - it turns out (thanks to Nick Campion for pointing out) there is nothing wrong with my snippet onPause\onResume
. I just called twice register/untegister
: once in the parent abstract class and one more in the child. As in class MyFragment extends AbsFragment
. So maybe have a look at your code
source to share