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 #4

Open
jemshit opened this issue Jan 24, 2019 · 2 comments
Open

Question #4

jemshit opened this issue Jan 24, 2019 · 2 comments

Comments

@jemshit
Copy link

jemshit commented Jan 24, 2019

Hi,
there is case regarding to ScopedFragment and "Kotlin android extensions" (old findViewById). In ScopedFragment, we cancel Job in onDestroy. AFAIK "Kotlin android extensions" assigns nulls to views in onDestroyView. So if there is coroutine running and trying to access a View after onDestroyView and before onDestroy, NullPointerException is thrown.
This can be difficult to see beforehand, maybe we should add warning at Readme file here?

@dmytrodanylyk
Copy link
Owner

Hi,

Thank you for reporting this issue. Any suggestions for a fix?

@jemshit
Copy link
Author

jemshit commented Jan 25, 2019

I can't think of one clean solution, depending on use case, maybe:

  • CoroutineScope can be created between onViewCreated()->onDestroyView() if coroutines change UI views
  • CoroutineScope can be created between onCreate() -> onDestroy() if coroutines does not touch the UI
  • Two CoroutineScopes in same Fragment for different purposes (mix of above two)

Another thing i stumbled upon is, there can be such flow in Fragment lifecycle:

  • onDestroyView()->onDetach()->onAttach()->onCreateView()
    onDestroy() and onCreate() is not called when fragment instance is alive, but view is destroyed and Fragment is detached.

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

2 participants