Pergunta

I use Otto bus to communicate events from activity to the fragments. The problem is, the fragments are managed by the ViewPager and the fragment can be recreated without ever executing its onPause() and/or onResume(). The unpleasant side-effect of that is that when bus.unregister(fragment) is called in onPause() the call periodically fails with IllegalArgumentException. I also suspect that calls to my @Subscribe annotated method can be missed since bus.register() call is in onResume() method which also can be not called. And, unfortunately there's no bus.isRegistered(fragment) method to do a safe check.

Is there a better way to register/unregister ViewPager managed fragment?

I'm aware of this post that discusses a similar setup but it does not include fragments running in ViewPager

Foi útil?

Solução

If you came here because you have a similar issue - turns out (thanks Nick Campion for pointing it) there's nothing wrong with onPause\onResume in my fragment. I simply had register/untegister called twice: once in the parent abstract class and another one in the child. As in class MyFragment extends AbsFragment. So perhaps look at your code

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top