Translate this page

Android Make a Splash Screen in Java

How to make a splash screen in android java – Android splash tutorial


image credit / Pixabay

 

A splash screen on android or a splash activity is an activity that is shown first when the app is opened.

It is not important to have a splash screen in android but having a splash screen can make your app look professional or standard, it can also be used as a waiting or progress indicator when an app is loading resources data in the background when launching.

This tutorial will help you to make a simple splash screen app.


 

How does a splash activity work?

As i mentioned above, splash activity is the first activity that is launched when an android app opened, the splash screen can be shown for some seconds to some minutes, or until the background loading of the app is complete, and then the splash Activity will open another activity, for example, the MainActivity – after a set time.

Some splash screen can be shown without an activity, for example – by changing some values in the resources folders, like – Styles.xml, colors, themes etc, but in this tutorial, we will learn to create a splash screen with set time.

 

So let’s begin the Splash tutorial

 

Start New android project

In android studio, start a new android project,

android new project
android start new project screenshot

 

Click Next and choose Empty Activity, click Next

pick activity android new project

Now wait until the project building finishes.




 

Create a New Activity

Select File > New > Activity > Empty Activity

This will be the Splash Activity of our app

 

Rename this activity to SplashActivity and click finish

 

Next step is editing the android manifest to set the SplashActivity as launcher Activity

 

Editing the Android Manifest

To load the splash Screen, the first activity (launcher activity) must be the SplashActivity. right now,  the first activity is MainActivity,  we need change the MainActivity to SplashActivity  in order for the Splash screen to be shown.

How to make an activity as launcher activity in android java

To make the SplashActivity as launcher activity, we need change it’s intent filter, to change the intent filter from MainActivity to SplashActivity, refer to this screenshot

 

Or you can copy this code to your manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            
        </activity>
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
    </application>

</manifest>

 

 

Next, we need edit the activity_splash.xml, and the SplashActivity.java files

 

Editing activity_splash.xml, and the SplashActivity.java

For the splash screen to show something when launched, we should add something like an imageview or textview or both into it. here we will add just a textview in the activity_splash.xml, so you can see the splash screen in action.

Open the activity_splash.xml and add this text view

<TextView
        android:layout_width="match_parent"
        android:layout_height="85dp"
        android:gravity="center"
        android:text="WELCOME SPLASH"
        android:textSize="70sp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="341dp" />

 

 




Open SplashActivity.java and enter this code below oncreate method

int SPLASH_TIME_OUT = 700;
       new Handler().postDelayed(new Runnable() {

           /*
            * Showing splash screen with a timer. This will be useful when you
            * want to show case your app logo / company
            */

           @Override
           public void run() {
               // This method will be executed once the timer is over
               // Start your app main activity
               Intent i = new Intent(SplashActivity .this, MainActivity.class);
               startActivity(i);
               // close this activity
               finish();
           }
       }, SPLASH_TIME_OUT);
   }}

 

So this is it, if you have any questions, just drop a comment below

Related Posts

Get Your Own Android Mobile App for Your Website Today

Are you looking to expand your online presence and reach more customers? In today’s digital age, having a mobile app is an essential tool to connect with…

Why making an app for your website can help your business to grow

In today’s digital age, it’s more important than ever to have a strong online presence. Whether you’re running a business, a blog, or a personal website, having…

person using macbook pro on person s lap

Fix android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference

Here is how to Fix Android Studio Error Attempt to invoke virtual method ‘boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference This error is caused by a number…

Android Spinner onItemSelected Listener Example

Spinner is an android UI element; it provides a drop-down List where you can choose an item from the list. You will need a listener to catch…

person in gray shirt holding a small paper with texts

Get Current Month Name in Java Android

The code below can be used to get the name of current month, for example, January, February, March etc. Just call this method and it will return…

The future of android developers is not good

Are you an android developer or looking to be an android developer? You should read this Myself is zid, I’m an android developer and been in this…

Leave a Reply

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