Pedro Francisco de Sousa Neto
02/01/2023, 2:28 PMfun Fragment.createFragmentScope(): Scope {
if (this !is AndroidScopeComponent) {
error("Fragment should implement AndroidScopeComponent")
}
// if (this.scope != null) {
// error("Fragment Scope is already created")
// }
val scope = getKoin().getScopeOrNull(getScopeId()) ?: createScopeForCurrentLifecycle(this)
val activityScope = requireActivity().getScopeOrNull()
if (activityScope != null) {
scope.linkTo(activityScope)
} else {
scope.logger.debug("Fragment '$this' can't be linked to parent activity scope")
}
return scope
}
I think the root cause is the usage of requireActivity()
inside createFragmentScope()
.