I am currently writing a Splash Screen for an app,...
# compose
l
I am currently writing a Splash Screen for an app, and I want to use this time to make a REST API call to our server that will check if the app is too outdated to properly access the API. I am currently using the single-activity model with a single Compose NavHost. I was wondering when the best time would be to trigger the viewModel to start the call. Should I trigger it when the viewModel is constructed, can the NavHost trigger the viewModel when I navigate to splash, or should I trigger this in some other way? I set up the SplashViewModel to call navigate on the navController to go to the next screen if it gets a valid response from the server.
d
Would probably be better to do this in a repository layer which launches as part of your main activity instead of calling from a splash screen.
l
Is a repository overkill for a single boolean result?
d
Depends on your use case. Do you want it shared to the rest of your app? If so I would still use the same pattern and have it separated to a model layer.
l
I guess it would make it easier to share the data with the rest of the app to use a repo. The main point of this call if to tell the API layer if the server has dropped support, so the app can notify the user to update and shut off all future API calls.