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

Scoped Object dependency is not getting injected in a Launcher Activity #2104

Open
Lokesh-30 opened this issue Jan 2, 2025 · 0 comments
Open

Comments

@Lokesh-30
Copy link

Lokesh-30 commented Jan 2, 2025

Describe the bug
I am using scope in my compose project to tie the viewmodel to the Activity, but when it is used in a Activity which is a Launcher it is crashing immediately but is not crashing when accessed later

Sample Code
class MainActivity : ComponentActivity(), AndroidScopeComponent {

override val scope: Scope by activityScope()
private lateinit var viewModel: MainViewModel

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    viewModel = scope.inject<MainViewModel>().value
    installSplashScreen().setKeepOnScreenCondition {
        viewModel.splashState
    }
    enableEdgeToEdge()
    setContent {}
    }

}

val viewModelModule = module {
scope {
viewModel {
MainViewModel(get(), get(), get(), get())
}
}
}

class MainViewModel(
private val savedStateHandle: SavedStateHandle,
private val apiRepository: ApiRepository,
private val broadcast: BroadcastHelper,
netWorkHelper: NetWorkHelper,
) : ViewModel() {
}

To Reproduce

  1. Download the below zip
  2. Launch the app
  3. App will crash
    Koin Dependency Injection.zip

Expected behavior
App should not crash and the inject is called in onCreate by still it is throwing exception

Koin module and version:
koin-core:3.5.6
koin-android:3.5.6
koin-androidx-compose:3.5.6

Screenshot 2025-01-02 183136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant