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

the android app restart/recreate all over each time I minimize the app #491

Open
Tweeel opened this issue Sep 23, 2024 · 3 comments
Open

Comments

@Tweeel
Copy link

Tweeel commented Sep 23, 2024

I am working on a KMM project and facing an issue with my Android app. The iOS app works perfectly, but the Android app restarts and recreates the whole activity each time I minimize it.

@nvkleban
Copy link
Contributor

Have you enabled "Don't keep activities" in developer settings on your phone?

@Tweeel
Copy link
Author

Tweeel commented Sep 23, 2024

No, and I just found the problem. Initially, I was passing the viewModels directly to the screens. I created a viewModelFactory to avoid the need to pass it each time, to facilitate testing later:

class ViewModelFactory : KoinComponent {
    inline fun <reified T : ScreenModel, reified P> getViewModel(parameter: P): T {
        val viewModel: T by inject { parametersOf(parameter) }
        return viewModel
    }

    inline fun <reified T: ScreenModel> getViewModel(): T {
        val viewModel: T by inject()
        return viewModel
    }
}

I noticed from another issue that removing "then" and calling the viewModel using the getScreenModel function from the screen content should fix the problem, and it actually did in my case. But it would still be nice if we could directly pass the viewModel in the parameter, as I mentioned earlier, to make testing easier.

@nvkleban
Copy link
Contributor

nvkleban commented Sep 24, 2024

I was passing the viewModels directly to the screens

Haven't worked with Koin, but have you checked documentation? it looks pretty straightforward

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

2 participants