Most of the Android apps use a splash screen before launching their main activity; you can see this with popular apps such as Skype, Facebook, Dropbox, etc.
While I was developing an Android APP POC for one of my customer, the requirement was to create a splash screen with their logo which stays on the screen for 3 seconds. Below are clear steps and code examples you can follow.
Prerequisites
- Android Studio (recommended recent stable version)
- A new or existing Android project
- A splash image (eg. splash_image.jpg) to place in your project's drawable folders
Overview
Two common approaches:
- Theme-based launch screen (recommended for fastest cold start)
- Separate Splash Activity (simple to implement — retains the author’s original approach)
This article preserves the original example and also shows a modern, safer implementation.
1) Create a new project in Android Studio
- File -> New Project
- Enter Application Name and Minimum SDK, Click Next
- Select Blank Activity, Click Next
- Click Finish
This creates the Android application with a blank activity. Next we will add the splash screen.
2) Create the splash layout
Create a layout file named res/layout/splash.xml with a simple LinearLayout that uses a drawable as the background. (The original article used a background drawable named splash_image.)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_image">
</LinearLayout>
Place your splash image file (for example splash_image.jpg) into your app/src/main/res/drawable or into density-specific folders like drawable-hdpi, drawable-xhdpi depending on your asset. For images that should not be scaled by Android, use drawable-nodpi.
3) Original (author's) Splash Activity example
The original sample shows a Splash Activity that waits for 3 seconds and then launches MainActivity. The unmodified original code (kept for reference) is shown below.
// SplashScreen.java
package marutsoft.vehicledata;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.widget.ImageView;
/**
* Created by Karjol G T on 11-05-2016.
*/
public class SplashScreen extends Activity {
protected int _splashTime = 3000;
private Thread splashThread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
Notes on the original approach:
- This uses a background thread and
sleep(3000). While it works in many cases, it is not the recommended pattern for modern Android apps. If misused it can block the UI or cause unexpected lifecycle behavior. onPause()callsfinish()to ensure the splash activity is removed from the back stack.
4) Manifest entry (make the splash activity the launcher)
Add the splash activity to your AndroidManifest.xml and make it the LAUNCHER activity. (Keep your package name.) The original manifest snippet:
<activity
android:name=".SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
5) Recommended modern implementation (non-blocking)
A safer and simpler approach is to use a Handler.postDelayed(...) from the UI thread (or new Handler(Looper.getMainLooper()) on newer platforms). Also prefer AppCompatActivity (or AndroidX ComponentActivity / AppCompatActivity) and call finish() after starting the main activity so the user does not return to the splash.
// SplashScreen.java (recommended modern approach)
package marutsoft.vehicledata;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity; // or import android.support.v7.app.AppCompatActivity for older projects
public class SplashScreen extends AppCompatActivity {
private static final long SPLASH_DELAY_MS = 3000L; // 3 seconds
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
finish(); // remove SplashScreen from back stack
}
}, SPLASH_DELAY_MS);
}
}
Why this is better:
- No manual Thread management or sleeping; uses Android's message queue and is safe on modern devices.
- Cleaner lifecycle handling when you call
finish()after starting the main activity. - Uses AppCompat so it's straightforward to compile in modern Android Studio projects.
6) Alternative best-practice: theme-based launch screen
For fastest cold start it is recommended to use a theme-based splash implemented with windowBackground in your app theme. This avoids inflating a layout or starting an activity before the first frame is shown. In short:
- Create a drawable (or layer-list) for the splash look
- Set it as
windowBackgroundin a launch theme - Use that theme for your LAUNCHER activity in the manifest
This method provides the fastest perceived startup time and is the recommended pattern for production apps. See the linked resources at the end for a dedicated guide.
7) Additional notes and troubleshooting
- Rotation: if your splash activity must survive rotation, avoid re-posting delayed callbacks multiple times. You can lock orientation or keep the activity lightweight.
- Long startup work: do not perform heavy initialisation on the UI thread during splash. Offload to background threads and show progress only if necessary.
- Assets: put different density images in drawable-*/ folders or use
drawable-nodpiif you do not want Android to scale the image. - Accessibility: when displaying logos in a view, provide content descriptions for screen readers. In a background-only layout, ensure the important content is accessible elsewhere in the app.
8) Run the app
Run the Android application to check the splash screen running at the beginning of the application.
That's it. Happy Coding..
Created by Karjol G T (original example preserved).