marcelpinto / RxFlux

RxFlux is a small framework in order to follow Flux design pattern with RxJava functionalities
Apache License 2.0
326 stars 38 forks source link

Third-party activity crashes onDestroy #11

Closed eprendre closed 8 years ago

eprendre commented 8 years ago

after upgrading to 0.3.2 I got several problems:

1.ClassCastException

Caused by: java.lang.ClassCastException: xxxActivity cannot be cast to com.hardsoftstudio.rxflux.dispatcher.RxViewDispatch

@Override public void onActivityDestroyed(Activity activity) {
    activityCounter--;

    List<RxStore> rxStoreList = ((RxViewDispatch) activity).getRxStoreListToUnRegister();
    if (rxStoreList != null) {
      for (RxStore rxStore: rxStoreList) {
        rxStore.unregister();
      }
    }
...
2.((RxViewDispatch) activity).onRxViewUnRegistered() moved to onActivityStopped

Thus behaviour is slightly different from unRegister onActivityPaused in 0.3.1. I have two activities responding to a same Action under onRxStoreChanged. It's OK with 0.3.1, cause one activity is unregistered onPause(when another activity launches). Is there any solution for 0.3.2?

marcelpinto commented 8 years ago
  1. I will add a check with instanceof RxViewDispatch. I wanted to force that all activities implement the method to avoid breaking the flow of flux. But I did not think on third parties.
  2. I decided to move it to onStop so the activity still reacts when there is sth on top but is still there. I will think it better and I will maybe revert it to onPause and onResume.
eprendre commented 8 years ago

Thanks for quick reply. For question 2, I think you're right, keep it plz. In 0.3.1 I did repeat the code in order to catch that same action. Now, after refactoring my code, it seems to be more reasonable.