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

[Android] lifecycle scopes are broken: using injected components in onCreate throws IllegalStateException #1448

Closed
Pfoerd opened this issue Oct 7, 2022 · 3 comments
Assignees
Labels
regression 💥 status:checking currently in analysis - discussion or need more detailed specs
Milestone

Comments

@Pfoerd
Copy link
Contributor

Pfoerd commented Oct 7, 2022

Describe the bug
java.lang.IllegalStateException: can't get Scope for FooActivity - LifecycleOwner is not Active is thrown when using any component injected from an Android lifcycle scope like activityScope/activityRetainedScope/FragmentScope in onCreate.

To Reproduce

class FooActivity : AppCompatActivity(), AndroidScopeComponent {

    override var scope: Scope? = null

    private val foo: Foo by inject()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        createActivityRetainedScope()
        foo.toString() // Exception is thrown here
    }

Expected behavior
Using injected components of Android lifecycle scopes in onCreate is possible

Koin project used and used version (please complete the following information):
3.2.2

Detailed Analysis and Proposed solution
At this point of LifecycleViewModelScopeDelegate _scope = koin.getScopeOrNull(scopeId) ?: createScope(koin) was removed (as part of this fix). So there is no cached instance of the lifecycle scope that can be used in the getValue call and as lifecycle component is in onCreate state the if (!thisRef.isActive()) returns false.

@Pfoerd
Copy link
Contributor Author

Pfoerd commented Oct 7, 2022

@arnaudgiuliani could you please have a look at this? This again blocks us from using Koin Android scopes :(

@Pfoerd Pfoerd changed the title Android lifecycle scopes are broken: using injected components in onCreate throws IllegalStateException [Android] lifecycle scopes are broken: using injected components in onCreate throws IllegalStateException Oct 7, 2022
@arnaudgiuliani
Copy link
Member

Sure, I'm on it 👍

@arnaudgiuliani arnaudgiuliani added this to the 3.2.3 milestone Oct 11, 2022
@arnaudgiuliani arnaudgiuliani self-assigned this Oct 11, 2022
@arnaudgiuliani arnaudgiuliani added the status:checking currently in analysis - discussion or need more detailed specs label Oct 11, 2022
arnaudgiuliani added a commit that referenced this issue Oct 18, 2022
@arnaudgiuliani
Copy link
Member

Scope API has been reverted and fixed to not conflict anymore 👍
It should be better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression 💥 status:checking currently in analysis - discussion or need more detailed specs
Projects
None yet
Development

No branches or pull requests

2 participants