Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Navigation change and life cycle edge case #19

Open
Ethan1983 opened this issue May 2, 2019 · 5 comments
Open

[Question] Navigation change and life cycle edge case #19

Ethan1983 opened this issue May 2, 2019 · 5 comments

Comments

@Ethan1983
Copy link

I'm running into an edge case and wanted to pick your brain on this, here is the use case

UI Event triggers a slow network op which starts with a loading state
UI is updated with a progress indicator
User backgrounds the app
Network op finishes while the app is in background (assume no process kill by android)
UI is subscribed to changes until onDestroy and gets notified of a navigation effect
Navigation Effect tries to perform fragment transaction while the app is paused
Things go haywire from here.

One approach to solve this was by having UI subscribe only until onPause and resubscribe from onResume. However, with this the effect notification is lost (no active subscriptions from paused state) when slow network op finishes while the app is backgrounded and re-subscription onResume fails as effect has no replay behavior from the view model.

This is kind of forcing navigation changes into view state. How do you go about this?

@Ethan1983
Copy link
Author

Not to mention, canceling the task onPause and restart onResume is a no go.

@ScottCooper92
Copy link

ScottCooper92 commented Jun 3, 2019

How are you subscribing/observing the navigation effects? I've just tested your scenario and although the LiveData is updated, the Observer isn't triggered until the app is resumed again, meaning no navigation events when the app is backgrounded.

@Ethan1983
Copy link
Author

Ethan1983 commented Jun 4, 2019

In my case, it is scoped to pause and resume. However re-subscribing from onResume is no good as the effect observable has no cache/replay behavior (in the case where task finishes while the app is backgrounded).

If you are using LiveData, it might work as it has a cache but it would break config change use cases where the same effect would be notified again to the new fragment/activity instance.

@kaushikgopal Any thoughts?

@jhowens89
Copy link

I was just poking around the Roxie github page so forgive me if I'm way off on what you're trying to accomplish, but would this suit your purpose?

https://github.com/akarnokd/RxJavaExtensions/blob/master/src/main/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubject.java

While I don't use Roxie, I do use RxRedux and I use a subscription held in my ViewModel to a DispatchWorkSubject for queueing up "navigation" in the form of view animations in onStart.

I've also been wanting to dig more into LifecycleCoroutineScope. I've found some great uses for it, but I haven't done enough investigation to know if it can be a solution to this particular problem too.

@Ethan1983
Copy link
Author

Ethan1983 commented Aug 5, 2019

I was just poking around the Roxie github page so forgive me if I'm way off on what you're trying to accomplish, but would this suit your purpose?

https://github.com/akarnokd/RxJavaExtensions/blob/master/src/main/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubject.java

While I don't use Roxie, I do use RxRedux and I use a subscription held in my ViewModel to a DispatchWorkSubject for queueing up "navigation" in the form of view animations in onStart.

I've also been wanting to dig more into LifecycleCoroutineScope. I've found some great uses for it, but I haven't done enough investigation to know if it can be a solution to this particular problem too.

@jhowens89 Thx, do you have a working sample code handling both foregrounded and backgrounded state. I'm interested in how your subscription to DispatchWorkSubject is setup to handle both cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants