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]

Android App Development: How to add icon for the application?

If you intend on your application being available on a large range of devices, you should place your application icon into the five different res/drawable... folders provided. In each of these folders, you should include a correctly sized icon:

  • drawable-ldpi (120 dpi, Low density screen) – 36px x 36px
  • drawable-mdpi (160 dpi, Medium density screen) – 48px x 48px
  • drawable-hdpi (240 dpi, High density screen) – 72px x 72px
  • drawable-xhdpi (320 dpi, Extra-high density screen) – 96px x 96px
  • drawable-xxhdpi (480 dpi, Extra-Extra-high density screen) – 144px x 144px

You may then define the icon in your AndroidManifest.xml file as such:


.... 
 

Android App Development: How to make an activity fullscreen

In order to make an activity full screen simply add the following lines to the onCreate() method as follows:

[cc lang=”java”]

// make full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

[/cc]