You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
@arnaudgiuliani could you please have a look at this? This again blocks us from using Koin Android scopes :(
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
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
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 inonCreate
state theif (!thisRef.isActive())
returns false.The text was updated successfully, but these errors were encountered: