1
votes

I'm building an app with Cordova and have managed to set-up splash screens on Android fine using:

<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="5000" />

in my config.xml and this works perfectly. The splash screen is displayed for the 5 second duration specified then hides.

I have got the app set up to listen for the "deviceready" event in order to execute the rest of my code. Again, this works fine.

The issue is that "deviceready" doesn't seem to wait for the splash screen to be completed - I am aware that this is probably normal behaviour. Sometimes the splash is still visible whilst the rest of my app has continued until the 5 seconds is up.

So what I want to know is; is there a way to execute code only after the splash screen has finished displaying for at least the defined duration?

Perhaps there is another Cordova event that is raised?

** Side note - I do want to make this as cross platform as possible so I would prefer not to make Android specific fixes for this if at all possible. **

2

2 Answers

2
votes

You can do use the cordova API to close the splash when you want.

Use a high value on XML configuration:

<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="60000" />

And in your JS:

document.addEventListener('deviceready', function () {
    navigator.splashscreen.hide();
});
0
votes

My preference is to not depend on splash screen to be there or not. If I want my image to show as a splash screen, and have code running behind it or depending on it, I put my splash screen image as my index.html page and code on that page, then jump/redirect/load the "first" page when my code wants to. Then I just use a solid color image as a splash screen, for minimal time, as Apple still wants it there.