-
Notifications
You must be signed in to change notification settings - Fork 226
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: Are AndroidLifecycleScopeProvider instances intended to be reusable? #114
Comments
They should be reusable. What version of arch components are you using? Due to a behavior and API change, 0.3.0 is not compatible with rc1. I've just made some changes in #111 that fixes both, and this looks related to the behavior change (previously, after PAUSE, it would mark state as DESTROYED, but now it slinky's back up to STARTED) |
I was using arch components beta1 because of that incompatibility with the rc1. The previous code that "worked" didn't use arch at all, it was just a custom scopeprovider with my own events. Your explanation makes sense. I'll try out develop today and get back to you ASAP, hopefully to beat 0.4.0. Thanks! |
I tried the current master with PR #111 but I still see the same issue. You can see for yourself in the sample app, modified slightly: https://github.com/tbsandee/AutoDispose/commit/894f45202df17b5fc6edd789ce0cb7a369b4ce09 With this change, if you leave the app and come back (triggering onStop, onStart) the app will crash. |
interesting, I'll look into it. Thanks for the repro case! |
So I understand the issue now, but not sure what to do about it. The issue is that the "last event" it sees when you resume in onStart is actually |
This moves backfilling out of a one-time thing in the constructor to something we do every time the lifecycle is peeked. It feels a bit weird though, but perhaps necessary because of the fact that arch lifecycle events are emitted _after_ the corresponding callback method. Resolves #114
#121 if you want to take a look. I'm not 100% sold on the solution, but also not sure if there's a better one |
…peekLifecycle (#121) * Make AndroidLifecycleScopeProvider reusable by backfilling from peek This moves backfilling out of a one-time thing in the constructor to something we do every time the lifecycle is peeked. It feels a bit weird though, but perhaps necessary because of the fact that arch lifecycle events are emitted _after_ the corresponding callback method. Resolves #114 * Fix imports * Clean up doc
LGTM. Thanks for looking into it! |
This is for AutoDispose 0.3.0.
A pattern I used for my custom scope providers for fragments/activities against AutoDispose 0.2.0 was to create a single scope provider (based on
BehaviorSubject
) and then share it between all observable chains for that entity. This worked fine, I think.Now I'm migrating to the new
AndroidLifecycleScopeProvider
and I find that if I create a single instance for a fragment or activity, when, for example, a secondonStart
event occurs I get the exception below.If I recreate the AndroidLifecycleScopeProvider instance for each subscription then it works fine, but it feels like it could be excess overhead. I do notice that this is the pattern you use in the samples, so perhaps it's intentional. There's no indication in AndroidLifecycleScopeProvider that it's stateful, so I'm just checking.
The text was updated successfully, but these errors were encountered: