koin icon indicating copy to clipboard operation
koin copied to clipboard

java.lang.IllegalStateException: Fragment Scope is already created

Open Zayankovsky opened this issue 1 year ago • 1 comments

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:

  1. Replace fragment with another one and add transaction to back stack.
  2. Pop the last transaction.
  3. Koin crashes, because in this case fragment is not recreated (thus the scope still exists), but its view is. onViewCreated is called again and createFragmentScope 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.

Zayankovsky avatar Sep 16 '22 16:09 Zayankovsky

This happens to me and I'm using ScopeFragment directly from Koin. :rage4:

Pitel avatar Sep 23 '22 08:09 Pitel

follow the issue

alessandroToninelli avatar Sep 26 '22 07:09 alessandroToninelli

Replacing it doesn't close the source scope then. Did you try with koin-android 3.2.2?

arnaudgiuliani avatar Nov 07 '22 17:11 arnaudgiuliani

Not reproducible with koin-android version 3.3.2.

Zayankovsky avatar Jan 10 '23 18:01 Zayankovsky