85
votes

Could anybody please advise how I can add a splash screen to my HTML5 Phonegap based Android App. I just want it to display for 5 seconds on load. Also - can anybody advise what dimensions the splash screen should be.

6
Just a friendly piece of advice, under no circumstances is it a good idea to put a splash screen on a mobile app. It's going to make your users super angry.Kurtis Nusbaum
I am sorry Kurtis, I am not sure what you are advocating. There are many very popular mobile apps that show a splash screen while they are loading without causing annoyance to their users. iOS even has an image caused Default.png specifically for this purpose.Devgeeks
@Devgeeks I agree with Kurtis Nusbaum for the case where you are showing a splash screen for the heck of it. If your application takes a long time to start up, a splash screen with an activity indicator probably better than nothing, which would be the likely reason for the popular applications you are talking about. Otherwise there are equal (or even greater) number of popular mobile apps that don't show splash screen. Basically get the user to the application as fast as you can. A 5 second splash screen every time is a bad idea as it will frustrate users in the long term.Kinjal Dixit
Please... don't do it! Splashscreen isn't a good idea :) It's right, that some popular apps has it, but it doesn't mean, that is a good idea ;)Štěpán Víteček
I think splash screens are a matter of taste/design. Of course most UX people will advice not using it but I disagree with them; a 1sec splash screen will not do any harm, instead, it will add a "personality" and sets a "theme" to your app making stand out of the thousands "bootstrapish" apps. In my device, more than 70% daily used apps have splash screens :)numediaweb

6 Answers

176
votes

In order to have a splash screen in a PhoneGap Android application you need to put your splash.png file into res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi. Where those directories represent low, medium, high and extra large dots per inch. You'll need to resize you splash.png (the file name is important here) for each directory or Android will stretch it for you.

The sizes of each image should be:

  • xlarge (xhdpi): at least 960 x 720
  • large (hdpi): at least 640 x 480
  • medium (mdpi): at least 470 x 320
  • small (ldpi): at least 426 x 320

Then in your main Java class, the one that extends DroidGap, you'll need to add one line and modify another. First add:

super.setIntegerProperty("splashscreen", R.drawable.splash);

this line should show up under super.onCreate but before super.loadUrl. Then you'll need to modify your loadUrl method to pause for 5 seconds before loading up the main page. It would look like this:

super.loadUrl("file:///android_asset/www/index.html", 5000);

That should do it for you.

I've recently made some updates to how the SplashScreen works on PhoneGap Android. The main app now loads while the splash screen is being shown. This is a big improvement over the previous blocking splash screen call. Read more about the changes on my blog.

6
votes

Phonegap (Apache Cordova) documentation has enough details about the splash screen and different resolutions for both Android and iOS at one place.

http://docs.phonegap.com/en/2.2.0/cordova_splashscreen_splashscreen.md.html

3
votes

In my Phonegap app, Android version, Eclipse debugger throws tantrums if you set the splash screen or even the 'loading' dialog before calling loadUrl.

Both will work in the actual app installed on a device, but they will break your debugging. So I've put them behind loadUrl, where they can do no harm and still show well before the app itself.

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html",5000);
    super.setStringProperty("loadingDialog", "Starting your app...");
    super.setIntegerProperty("splashscreen", R.drawable.splash);
    ...
}...
3
votes

I have also face this issue in phonegap android ..but now i got solution.

super.setIntegerProperty("splashscreen", R.drawable.splash);(find image under drawable folder named splash,so put splash.png under drawable folder)
super.loadUrl("file:///android_asset/www/index.html",15000);(splash screen will show 15 sec.

Please edit your main java file under src folder in your project directory .

public class radiobiafra extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
         super.onCreate(savedInstanceState);

         super.setIntegerProperty("splashscreen", R.drawable.splash);
         super.loadUrl("file:///android_asset/www/index.html",15000);
     }
}
0
votes

This will probably meet your needs. It lets you customise and add all the relevant config.xml setting, images and splashscreens in a nice intuitive interface.

I recommend downloading the file and installing manually. The web based air installer doesnt seem to work.

http://aj-software.com/configap/index.html

0
votes

Using Cordova >= 3.6, and building your app with the Cordova Command-Line Interface, it's possible to configure the splash screen from the config.xml file. This is an example for Android:

<platform name="android">
    <!-- you can use any density that exists in the Android project -->
    <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
    <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi"/>
    <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>
    <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi"/>

    <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
    <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
    <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
    <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
</platform>
<preference name="SplashScreenDelay" value="10000" />

There is also a dedicated plugin to show/hide the splash screen programmatically.

See the Cordova documentation for more information.