Giter Site home page Giter Site logo

Comments (8)

felipecsl avatar felipecsl commented on May 27, 2024

Are you calling GroupLifecycleManager from all your lifecycle methods?
Check out MainActivity in the sample app, you should be doing something similar

from rxgroups.

felipecsl avatar felipecsl commented on May 27, 2024

https://github.com/airbnb/RxGroups/blob/master/sample/src/main/java/com/airbnb/rxgroups/MainActivity.java

from rxgroups.

erseno avatar erseno commented on May 27, 2024

@felipecsl
Hi, many thanks the reply. I will give a try this weekend and i'll report back my findings.

I am only forwarding the fragment ones but not the activity

from rxgroups.

felipecsl avatar felipecsl commented on May 27, 2024

that should be fine too

from rxgroups.

erseno avatar erseno commented on May 27, 2024

@felipecsl
Hi, I double checked the lifecycle calls, I am calling them all for the fragment and activity. I am still experiencing the mentioned issues

BaseActivity

 @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG,"onCreate");
        mGroupLifecycleManager = GroupLifecycleManager.onCreate(
                RxGroupApplication.getInstance().getObservableManager(),
                savedInstanceState, this);
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i(TAG,"onPause");
        mGroupLifecycleManager.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG,"onResume");
        mGroupLifecycleManager.onResume();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG,"onSaveInstanceState");
        mGroupLifecycleManager.onSaveInstanceState(outState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG,"onDestroy");
        mGroupLifecycleManager.onDestroy(this);
    }

BaseFragment

  @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG,"onCreate");
        mGroupLifecycleManager = GroupLifecycleManager.onCreate(
                RxGroupApplication.getInstance().getObservableManager(),
                savedInstanceState, this);
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i(TAG,"onPause");
        mGroupLifecycleManager.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG,"onResume");
        mGroupLifecycleManager.onResume();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG,"onSaveInstanceState");
        mGroupLifecycleManager.onSaveInstanceState(outState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG,"onDestroy");
        mGroupLifecycleManager.onDestroy(getActivity());
    }

The link to the app has been updated too

from rxgroups.

felipecsl avatar felipecsl commented on May 27, 2024

OK @erseno I spent some time debugging your project to see what's going on, here's what I found out so far:
You're doing:

userObservable
    .compose(mGroupLifecycleManager.<ArrayList<User>>transform(TAG))
    .delay(5, TimeUnit.SECONDS)

If you just invert the order of compose and delay, so that it looks like it's shown below, then it works:

userObservable
    .delay(5, TimeUnit.SECONDS)
    .compose(mGroupLifecycleManager.<ArrayList<User>>transform(TAG))

As a side effect, you'll have to manually move your code in onNext into the main thread since it will be called from a background thread.

This is just a workaround to get you unblocked, in the meantime I'll look into why this is happening.
What I've seen so far is that ObservableGroup#add is causing the onTerminate callback to be invoked immediately after managedObservable#unlock is called.
I'll keep digging on to why this is happening and will update this issue when I have a fix.
Thanks for your great bug report and providing the test project.

from rxgroups.

felipecsl avatar felipecsl commented on May 27, 2024

OK so this is not a bug and working as intended. Remember that RxJava operators can't see the future, so they can't see anything that's applied after them. In this case specifically, the delay call.
What's happening is that the Retrofit response is returning very fast (under 200ms average on my machine) and you're applying the RxGroups transformer on it. By the time that the response is received from Retrofit, RxGroups immediately removes that Observable from the list of "in flight" requests since it's already seen a terminal event (onCompleted). So, when you rotate, delay() is grabbing that event and holding onto it for 5 seconds, thus finally delivering it after the Fragment has been already destroyed, causing the Exception.
When you move the delay call above compose, now RxGroups is aware of the entire stream and is able to correctly manage rotation since it will prevent delay() from delivering the event after onDestroy().
So TL;DR: not a bug 😄

from rxgroups.

erseno avatar erseno commented on May 27, 2024

Hi thanks for the comments and apologies for my late reply.

I've removed the delay call and made the emulator simulate a slow network connection (GPRS) so that the call takes a while. I am still encountering the same mentioned issues.

I've updated my project again.

Below the difference.

  Observable<ArrayList<User>> userObservable = RetrofitManager.INSTANCE.getApiService().getUsers();
        Observable<ArrayList<User>> userObservableTwo = RetrofitManager.INSTANCE.getApiService().getUsers();
        Observable<ArrayList<User>> userObservableThree = RetrofitManager.INSTANCE.getApiService().getUsers();
        Observable<ArrayList<User>> userObservableFour = RetrofitManager.INSTANCE.getApiService().getUsers();
        Observable<ArrayList<User>> userObservableFive = RetrofitManager.INSTANCE.getApiService().getUsers();

//        Observable.zip(userObservable, userObservableTwo, userObservableThree,userObservableFour,userObservableFive, (users, users2, users3,users4,users5) -> {
//            ArrayList<User> usersCombined = new ArrayList<>();
//            usersCombined.addAll(users);
//            usersCombined.addAll(users2);
//            usersCombined.addAll(users3);
//            usersCombined.addAll(users4);
//            usersCombined.addAll(users5);
//            return usersCombined;
//        })
//                .compose(mObservableGroup.<ArrayList<User>>transform(TAG))
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribeOn(Schedulers.newThread())
//                .subscribe(mObserver);

        userObservable
                .compose(mObservableGroup.<ArrayList<User>>transform(TAG))
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(mObserver);

The commented stuff was just to simulate a longer network request before I realised that it is possible for the emulator to simulate a slower internet.

Cheers!

from rxgroups.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.