JakeWharton / RxBinding

RxJava binding APIs for Android's UI widgets.
Apache License 2.0
9.69k stars 971 forks source link

RxView.clicks(my_button) binding stops working after fragment replace #432

Closed davida5 closed 6 years ago

davida5 commented 6 years ago

Any idea why RxBinding registered with RxView.clicks(buttonView) stops triggering after fragment replace inside activity. My activity can replace fragment multiple times.

My fragment code looks like the following:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    ....
    //this code works before and after fragment replace
    plus_view.setOnClickListener(v -> {presenter.increaseLevel(getCurrentLevel());});
    //        below code stops working after fragment replace
    //        compositeDisposables.add(RxView.clicks(plus_view).subscribe(o ->
    //        {
    //            System.out.println("presenter getCurrentLevel Called");
    //            presenter.increaseLevel(getCurrentLevel());
    //
    //        }));
    ....
 }

inside my Activity I do the following:

    @Override
    public void replaceDetailWithEditFragment() {
        ....

        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.details_fragment_container, detailEditFragment, DETAIL_EDIT_FRAGMENT_TAG);
        fragmentTransaction.commit();
        mFragmentManager.executePendingTransactions();
        ...
     }

full source with latest commit can be found here: https://github.com/davida5/AwesomeNotes/tree/repositoryPattern

davida5 commented 6 years ago

After further digging I realized the binding was lost because I did not recreate the CompositeDisposable() after fragment was destroyed. All working now, closing the issue.