Game startup too slow, even splash screen

Hello,
The game takes too long to start on android (almost 4-6 seconds). I am ok with this delay but while the game is loading I would like to show a loading/splash screen. I have created a splash scene for this but it always displays after cocos2d-x has loaded completely (ie. after the 4-6 seconds delay). How can I show a splash scene immediately on start up before cocos2d-x has loaded?

Have you tried displaying something in the Android Java code?

What are you doing in initialization? Are you loading sprite sheets in the AppDelegate?

Hi, Im not displaying anything in Android code. And I’m not loading any thing in AppDelegate.
I am simply loading the first scene in AppDelegate’s AppDidFinishLaunching method. How can I atleast display an image while cocos2d-x is loading?

On Android it takes some time to load cocos2dx lib and other stuff you should do this other way. When your application start, display a simple Activity with your loading screen next load your all resources and run cocos :).

Thanks David, I tried what you have mentioned. I start the app in a Java Activity and display the splash image for a few seconds. Then, I start the main cocos2dx activity. But, I still get a blank screen after the splash image. Only after cocos2dx has completely loaded, my first scene from the AppDelegate is shown.
Am I doing this right? I think I am missing something here.:frowning:

Here my example

Loader.java

public class Loader {

    private static boolean m_isLoaded = false;

    public static synchronized void load() {
        if (m_isLoaded) {
            return;
        }
        m_isLoaded = true;
        System.loadLibrary("game");
    }
}

LoadingScreen.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class LoadingScreenActivity extends Activity {

    private Handler m_handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(RW.layout.loading_screen_activity);

        m_handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                startGame();
            }
        }, 2200); //Here we want that loading screen display at least 2 seconds
    }

    private void startGame() {
        Loader.load(); //Screen here hangs so you have here your LoadingScreen
        startActivity(new Intent(this, EduKoala.class));
    }
}

Also remember to add load in your Game.java because android sometimes skip SplashScreen please read about Android life cycle :slight_smile:

My Game.java

public class EduKoala extends Cocos2dxActivity {

    protected void onCreate(Bundle savedInstanceState) {
        Loader.load();
        super.onCreate(savedInstanceState);
... rest of the code

Thanks Dawid. I tried out your code. I can see the splash screen for 2 seconds and the libgame.so library loads in that time. But, I still see a blank screen after launching the main cocos2d-x activity (‘Edukoala’ in your example). I think it has to do something with loading the resources (images, music, etc.). I had noticed that as the size of my resources grew over time, the startup time also increased with it.
Any ideas why this may be happening? Am I missing something here?

Of course if you have a lot of resources you must load them in this way

load few images
draw
load few images
draw

You can’t load them at once. How big your resources are? Also please use Spritesheet for better performance.

For example in cocos on start you can display simple scene and start with some delay your load function that loads your resources. How big your application is?

@asloobq sorry to trouble you.But i have met the same problem as you have.Would you like to give some help?