Search code examples
androidsplash-screen

Android 12 splash screen setKeepVisibleCondition


I'm trying to implement a splash screen using android 12 SplashScreen compat library. I want to fetch some data from API each time my app starts. So the splash screen should wait until the API calls finish. I found this splashScreen.setKeepVisibleCondition() function in docs, but don't know how to implement KeepScreenOnCondition. How can I make my splash screen to wait? Any help would be appreciated.


Solution

  • found the solution.

    private var isLoading = true
    
    override fun onCreate(savedInstanceState: Bundle?) {
        val splashScreen = installSplashScreen()
        splashScreen.setKeepVisibleCondition { isLoading }
    }
    
    private fun doApiCalls(){
        ...
        isLoading = false
    }