koin
koin copied to clipboard
java.lang.IllegalStateException: Fragment Scope is already created
Describe the bug Koin crashes with the following stack trace:
java.lang.IllegalStateException: Fragment Scope is already created
at org.koin.androidx.scope.FragmentExtKt.createFragmentScope(FragmentExt.kt:36)
at org.koin.androidx.scope.ScopeFragment.onViewCreated(ScopeFragment.kt:46)
at com.mapbox.onetap.map.presentation.ui.DropInFragment.onViewCreated(DropInFragment.kt:258)
at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3128)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:552)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1881)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1814)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1751)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:538)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
To Reproduce Steps to reproduce the behavior:
- Replace fragment with another one and add transaction to back stack.
- Pop the last transaction.
- Koin crashes, because in this case fragment is not recreated (thus the scope still exists), but its view is.
onViewCreated
is called again andcreateFragmentScope
crashes, because the scope is already created.
Expected behavior
Koin should not crash if the scope is already created. Another option is to create the scope in onCreate
instead of onViewCreated
.
Koin project used and used version (please complete the following information):
koin-android version 3.2.1
. This does not happen with 3.2.0.
This happens to me and I'm using ScopeFragment
directly from Koin. :rage4:
follow the issue
Replacing it doesn't close the source scope then. Did you try with koin-android
3.2.2?
Not reproducible with koin-android version 3.3.2
.