X
    Categories: Beginner

Enhancing User Experience with Android Splash Screen

 

Splash Screen may be a image or sometimes a video depending upon the app. Android Splash Screen is a first screen that splashes when a user start a app.

As it is the first screen try to add some creative image or your app logo something which attracts the user in first impression.

Some apps try to load android splash screen image from server so that they can change it everyday or frequently to make a fresh look for the user every time.

 

Android splash screen :

Generally every app will have a splash screen which will open up for certain amount of time, within which app functionality can be loaded like checking a user is logged in or not, checking whether the device is connected to internet and also starting various background services depending upon the app functionality.

In this tutorial on splash screen android studio i am showing a splash screen which will be shown for about 5 seconds and then moves to the next screen.

 

SplashScreen.java :

Splash screen sleep time is set to 5 seconds

sleep(5*1000)

 

Then the activity is moved to the next preceding screen

 

Intent i=new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);

 

public class SplashScreen extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splashscreen);

		Thread background = new Thread() {
			public void run() {

			try {
			sleep(5*1000);

			Intent i=new Intent(SplashScreen.this,
					MainActivity.class);
			startActivity(i);
			finish();

				} catch (Exception e) {

				}
			}
		};

		background.start();

	}

We can add a image-view  and assign image to it but i want to make it much simpler. So, had assigned image to layout as background.

splashscreen.xml :

It is a better practice to add a imageview and then assigning it to src tag to display image without any blur or expanding of the image if you need any help regarding the process comment below.

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/splash" >


</LinearLayout>

 

Now after splash screen loading we have to move to another screen i.e., MainActivity.java

MainActivity.java :

Here we have no initialization we are just moving to MainActivity after Splash Screen.

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

 

Adding a textview to activity_main.xml

 

activity_main.xml :

Add a single textview to show a sample message in android splash.You can add any other components.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.androidcoding.abhi.splashscreen.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Home Screen"
        android:layout_gravity="center"
        android:layout_marginTop="150dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

 

 

AndroidManifest.xml :

No special permission required but, add android splash screen Activity to Manifest file this is the important task which will make splash screen load on app startup and make it as a launcher to load it first.

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidcoding.abhi.splashscreen"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.androidcoding.abhi.splashscreen.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>
        <activity
            android:name="com.androidcoding.abhi.splashscreen.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

Android splash screen output :

The screen depicts the usage of android splash.

If you have any query’s in this tutorial on splash screen let us know in the comment below.

Also do share and like to get more interesting tutorials on android.

abhishek:
Related Post

This website uses cookies.