incentivelabs.de

Blog about nerd stuff, programming and related tools

Android Splash Screen

Published / by glethien / Leave a Comment

Recently I’ve came across a minior discussion about Splash Screen in Android.

We talked about the usefulness of those splash screens. Some want to use them to display the company logo or app logo, so the user has to stare several seconds on the logo. If the screen stays for 3 secs and the user opens the app 3 times a day, this makes 9 seconds of waiting or 35 secs a week. If you have 1 million users, your users will wait for 35000000 secs or 583333 minutes or  9722 hours A WEEK! Just let this huge numbers sink in…

What a waste of time!

On the other hand Google advocates using splash screens. You can find it here in the material design guidelines. All Google apps like Youtube, Mail or others using splash screens! But they only let the user wait the minimal time necessary for the app to load! Not a second longer.

 

Implement a splash screen

 

So at first you will need a simple layout in xml which defines your splash screen. A minimal one with the app logo centered is enough! This could look like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".SplashActivity"
    android:gravity="center_vertical|center_horizontal">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="false"
        android:background="@drawable/logo" />
</LinearLayout>

This will create an layout with a 200dp squared logo centered. Don’t overload the screen with text, logo and other stuff! In the best case this screen will stay less than a second and the user don’t have enough time to read everything!

In Java you just load your app and then proceed to the next activity as soon as possible

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        // Here do some bootup stuff, but nothing long loading.
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
}

And that’s it. You may request the permissions before calling the intent, but there is no more magic. With this you have an activity as splash screen which only stays for the minimal needed time and not wasting your users time.

Leave a Reply

Your email address will not be published. Required fields are marked *