-
Notifications
You must be signed in to change notification settings - Fork 69
disposing render subscription after onDestroyView #44
Comments
How about just moving |
calling Do you think the |
The only thing I can think of is that if we move those to |
If the initial intent filter is used we take only the first initial intent and the rest won't be triggered as long as the ViewModel is not destroyed. |
Oh right, I forgot about that one. Would you like to submit a PR? |
yes, happy to do it 👍 |
I came here wondering about the same issue. I think the proposed solution makes sense. |
I was having trouble with binding in onStart and unbinding in onStop. When I leave the app and come back, it's not subscribed to the render calls. I'm not sure why, but switching to onActivityCreated/ onDestroyView worked for me, which is the scope of my ViewModel. The only reason I used onActivityCreated instead of onCreateView was because I needed the activity available for unrelated reasons. |
Figured out my issue with onStart/onStop. I was calling |
@nateridderman the |
Thank you all. |
I had an after thought and I see the fix wasn't the right one, it also created #49 . Not sure how to deal with fragment lifecycle still; I'd rather move away from it maybe. |
I will go and figure out why the refresh event is triggered. private fun initialIntent(): Observable<TasksIntent> {
return Observable.fromCallable { TasksIntent.RefreshIntent(false, "INITIAL") }
.cast(TasksIntent::class.java)
.startWith(TasksIntent.InitialIntent)
} OnStart should not be called more than once before onStop and could not reproduce it. I am not
Could you please give an example of what else could be improved? I am also interested in what is your idea behind the move away from fragments. Happy to help solve these issues EDIT: I could not reproduce the same issue with pullToRefresh. |
This very issue because caused by the weirdness of fragments' lifecycle is a good enough reason for me to not use them. |
override fun render(state: xxxViewState) { |
Issue:
this might be an issue if an async event comes back and triggers a render between the
onDestroyView
andonDestroy
because the fragment view is already destroyed with theonDestroyView
but we did not unsubscribe the render subscription.Clearing the disposables in the fragments happening with the
onDestroy
event:override fun onDestroy() { super.onDestroy() disposables.dispose() }
fragment lifecycle:
... onStop onDestroyView onDestroy
Reproducing the issue:
this could be reproduced if you call detach after binding the ViewModel and delaying the state observable.
detach: detach triggers the destruction of the view without calling onDestroy
delay: simulates the late render event
Solution suggestion:
Moving up the
bind
event to theonStart()
and the unsubscription to theonStop()
?The text was updated successfully, but these errors were encountered: