Splash
I have main activity UI startup operations that take between 5-10 seconds (that need to be handled on the main UI thread) - so I would like to use a splash screen rather than the default black or non-responsive main UI.
A good solution to the splash screen is provided below
- which is to first set
setContentView(R.layout.splash)
, - then do the necessary main UI processing (on UI thread but with main view that is not visible)
- and when that is ready show
setContentView(R.layout.main)
Android Splash Screen before black screen
Splash with Fragments
I'm also using fragments, which normally require setContentView(R.layout.main)
to be called before fragment instantiation - so that the fragment manager could find the view stubs in R.layout.main
to inflate the fragments into (strictly speaking view stubs are a different thing).
- But I cannot call
setContentView(R.layout.main)
before creating the fragments, because that replaces the splash screen with the (not-yet-ready) main screen. - My fear is that what I want to do cannot be done?
- Unfortunately, there is no overload like
fragmentTransaction.add(viewNotViewId, fragment);
Almost-Answer
Here's all but the key, which is that setContentView
is called before the fragment transactions:
How do I add a Fragment to an Activity with a programmatically created content view