Android native Splashscreen

I need some help on creating a native splashscreen.

I mean the splash that use the png in drawable path.

In AndroidManifest.xml we have:

android:icon="@drawable/icon"

and it works.
But the default theme:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

Doesn’t have the style:

<item name="android:windowBackground">@drawable/splash</item>

So what is the right way to proceed?

I have created styles.xml in res/values, with the following code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>
</resources>

And then in AndroidManifest.xml, my activity is:

<activity
  android:name="org.cocos2dx.cpp.AppActivity"
  android:label="@string/app_name"
  android:launchMode="singleTop" 
  android:screenOrientation="sensorPortrait"
  android:configChanges="orientation"
  android:theme="@style/Theme.Splash">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

The splash works, but then the activity don’t go fullscreen, it seems like a quarter of screen with the splashscreen behind, really strange.

Please help me with the right procedure to achieve this, thank you, I really don’t know what’s wrong.

It works for me, I’m using a theme with white background:

<color name="white">#FFFFFFFF</color>
<style name="SplashTheme" parent="android:style/Theme.NoTitleBar.Fullscreen">
  <item name="android:windowContentOverlay">@null</item>
  <item name="android:windowBackground">@color/white</item>
</style>

Please note: using a drawable in your splashscreen is not advised (Google recommends against it), because there is no way to keep the ratio using android:windowBackground. Instead, it’s better to have a dominant color (or transparent, some apps like Skype seem to do that), then show a proper splashscreen image using Java code (bonus: you can add a fade in transition).

I found the best splashscreen is to:

  • have a style on your main activity which defines the main color (white for me)
  • have an Android layout with same style and an ImageView. FadeIn the ImageView during onCreate
  • make the C++ code discard the splashscreen once your first scene is loaded (to avoid having a black screen between splashscreen and first scene). Some people use a fixed timer, but that’s bad practice in my opinion. Just enforce a minimum duration so that FadeIn transition is finished.

Thank you for answering me @Fradow

Ok I understand, but with Java code I’ve seen a lot of ppl doing it with a fixed timer and as you said is not good because every device has different loading speed.

The difficult thing for me is that if I do a separated Splashscreen.java activity, I don’t know how to load the main activity showing in the meantime the splash.

I come from a Cordova approach, that use the drawable folder, and for the device ratio I normally have used a splash9. (splash.9.png)

The strange thing in cocos2dx, is that the splash9 loads but the main activity of cocos2dx will display not in fullscreen, but it’s reduces to 1/6 of the screen… maybe some problem with drawable and opengl.
I’m trying to change something in Cocos2dxActivity, Cocos2dxRenderer and Cocos2dxGLSurfaceView, but no good results so far :frowning:

I don’t know about splash9 way, it may work, it’s up to you to try.

What I do is that my Activity is a subclass of Cocos2dxActivity (I do not have a separate Splash activity), and add the splashscreen (a Dialoag) on top of the GLView while the C++ code loads. Once it finishes loading, a do a JNI call to tell the Java side it’s time to dismiss the splashscreen.

Thank you for the hint @Fradow

Because I’m trying all the day but without success.
I’ve created a Splash Activity, but it’s always a fake Splash Screen.

If I use something like that:

  new Handler().postDelayed(new Runnable() {
   public void run() {
   finish();
   Intent mainIntent = new Intent(SplashScreen.this,org.cocos2dx.cpp.AppActivity.class);
   startActivity(mainIntent);
   }
  }, 2000);

or also without a timer:

mHandler = new Handler();
myRunnable = new Runnable() {
    @Override
    public void run() {
        Intent intent = new Intent(SplashScreen.this, org.cocos2dx.cpp.AppActivity.class);
        startActivity(intent);
        finish();
    }
};

But it doesn’t work like a real SplashScreen/LoadingScreen.

It loads the drawable (also the Splash9), but THEN it loads the cocos2dx main activity where I have all the preload data that I can’t move to other places.

Your solution seems good if the Splash is showing WHILE the code loads.
So I have to look something to create a Dialog on top of the GLView…

Just a doubt, so for loading mainactivity in background don’t you start a new Intent in the Splash Activity?

That’s the whole point of a splashscreen: showing it while the code loads.

I’m not sure you can load another Activity in the background while showing another. My method does not use a splash activity. I do not have to load a new Intent.

Here is my SplashDialog class: https://github.com/FenneX/FenneX/blob/cocosV3.3/proj.android/src/com/fennex/modules/SplashDialog.java

It is instanciated and destroyed by my main activity: https://github.com/FenneX/FenneX/blob/cocosV3.3/proj.android/src/com/fennex/modules/ActivityResultNotifier.java (in my apps, the main activity is a subclass of that one, and implements methods to tell what’s the theme and splash ImageView are, so that FenneX does not have any dependency to the project resources)

Thank you very much, I’ll keep updated, when I’m done!