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

Add Admob ads in recyclerview in android

How to add admob native ads to recyclerview in android java Adding admob native ads into android recyclerview isn’t easy like other admob ads. You will need…

Download WebView Flutter Source Code for Android and iOS

Easily create android and iOS WebView app for your websites, the much-awaited flutter WebView source code is here. Are you looking for a flutter WebView source code…

Fix uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:_flutter_android]

This error can be fixed by modifying build.gradle file in the flutter In android studio: go to android>app>build.gradle and modify it as follows:

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…

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…

Leave a Reply

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