There is no direct API to disable the default splash screen but we can handle this with some workarounds.
Approach 1:
Add <item name="android:windowIsTranslucent">true</item> to your style
<style name="Theme.RemoveSplashScreenTheme" parent="@style/BaseTheme">
<item name="android:windowIsTranslucent">true</item>
</style>
Apply this to splash screen Activity.
<activity
android:name="com.test.SplashScreenActivity"
android:launchMode="singleInstance"
android:theme="@style/Theme.RemoveSplashScreenTheme"
android:noHistory="true" />
this will replace the default splash screen with a transparent screen. This workaround will eliminate the 2 splash screen issue if the app already has one.
But it will make the system splash screen invisible and it may look like the app is not responding. If anyone facing this issue then follow the next workaround.
Approach 2:
So we can resolve this issue by suspending the app to draw an existing splash screen and show the system splash screen until the app is ready.
private void setupOnPreDrawListenerToRootView() {
View mViewContent = findViewById(android.R.id.content);
mViewContent.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
Log.v("onPreDraw","onPreDraw called");
if (isAppInitialized) {
mViewContent.getViewTreeObserver().removeOnPreDrawListener(this);
startActivity(new Intent(this, MainActivity.class));
return true;
} else {
// The content is not ready; suspend.
return false;
}
}
});
}
Here we need to update isAppInitialized to true once the app is ready then we can remove the listener and launch the MainActivity until then it will hold the. app to draw an existing splash screen and execute all the app initializations.