Android App Development: Creating Splash Screen

In this tutorial, you’ll learn how to create a splash screen which can be used to show your logo and play an intro song.

Firstly create the default blank android project with the default main activity.
For this splash screen we are using a background image (1080×1920) called ‘splash.png’, which is placed in the ‘res/drawable-hdpi’ folder. Also place a song called ‘splashsound.mp3’ in the ‘res/raw’ folder.

Create the ‘splash.xml’ file in the ‘res/layout’ with the following content:
[cc lang=”xml”]
< ?xml version="1.0" encoding="utf-8"?> [/cc]

Then add the Splash.java file as below to your package in the src folder.
[cc lang=”java”]
package com.codinglogbook.example;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {

MediaPlayer introSong;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// background music – simpler to setup
introSong = MediaPlayer.create(Splash.this, R.raw.splashsound);

introSong.start();

// SoundPool used for small clips 1 or 2 seconds
final Thread timer = new Thread() {

@Override
public void run() {
try {
sleep(2000);
} catch (final InterruptedException e) {
e.printStackTrace();
} finally {
final Intent openStartPoint = new Intent(“.MAINACTIVITY”);
startActivity(openStartPoint);
}
};
};
timer.start();
}

@Override
protected void onPause() {
super.onPause();
introSong.stop();
finish();
}
}
[/cc]

Finally update the ‘AndroidManifest.xml’ to include the splash activity as the launcher and the main activity as the defalut:
[cc lang=”xml”]
< ?xml version="1.0" encoding="utf-8"?>













[/cc]