Android launch screen doesn't have an image (black screen instead)

I have searched and tried a lot but can’t figure out to have a decent launch screen for android. The following code just gives a 3 seconds (propably it should take longer) the background image which is great, then disappears but after that only a black screen remains. Of course this 3 seconds idea is far from ideal, the image should be displaying only for the time the system needs to load. Please help me out!

public class AppActivity extends Cocos2dxActivity {

public static View splash;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    
    splash= getLayoutInflater().inflate(com.dhangout.R.layout.activity_splash, null);
    setContentView(splash);
    

    new Handler().postDelayed(new Runnable() {
        
        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */
        
        @Override
        public void run() {
            // This method will be executed once the timer is over

            ViewGroup parent = (ViewGroup) splash.getParent();
            parent.removeView(splash);
            
            
        }
    }, 3000);

}

}

Are you trying to make a splash screen before game?
Why not just create a scene in C++ code?

No not a splash screen, I did mention a launch screen didn’t I?

Use a custom application background instead of black one???

Since the application has not started yet (still loading) I doubt if a custom application background will work, and also I even don’t know what that is?
Please try to run a cocos2d-x project for android and you will see what I mean. For iOS this is easy and you are able to select the proper launch images. But for android you can’t and it can take up to maybe even 10 seconds before your application (depending how large it is appearantly) finally starts and the user is, not knowing what’s happening, watching at a black screen in the meanwhile for all this time.

Certainly, i actually know what you mean. the solution is set a custom background of your app theme.
Attention!!! Not the entry activity or your game activity! I mean the Application’s xxx!

Thank you, I will try it!

Hi @rene_73,

an Android Launch Screen is made with a custom style/theme, see https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd (incl. first comment). This way it will be shown until the main activity leave the onCreate(). I implemented also a min delay for 0,5sec, so the image is shown a least this time.

@mars3142 thank you, much appreciated, it was a bit hard to find any samples. I will give it a try today and will make a post when I know more.

@rene_73 It’s my daily business (writing Android apps), so I know the keywords and needed posts. If you need any further help with the 0,5sec min delay, I can post sample code. But you wrote, that you app needs 3sec, so it shouldn’t be needed :wink:

Some sample code would come in handy;) I am confused at the setTheme(R.style.Theme_MyApp);
Don’t know where Theme_MyApp comes from that previous link you mentioned.
I get ‘cannot find symbol’ with the error pointing at the R.

It’s still not working. I found a sample that I implemented from http://stackoverflow.com/questions/9561003/android-app-custom-background (the accepted answer), no errors but still a black screen though I have an image. Isn’t their any full examples do you know please?

xml/values/styles.xml

<?xml version="1.0" encoding="utf-8"?> @drawable/yourcustombackgroundimage.png

and use this style in the manifest file.

Do you still need help? I can create a sample, but it will take at least two days, if this is okay.

Would be great to have an example if it’s not too much of a trouble, thanks!