How to implement android flash screen

Implement Android Splash Screen

android, TUTORIALS

How to implement Android Splash Screen

Welcome Everyone to another fun tutorial in android basics. In this tutorial How to implement Android Splash Screen we gonna teach you how to implement the android splash screen for your android application. In general the splash screen is nothing but, before start our application starts it shows an welcome screen like company or application logo for a while period. To implement a splash screen basically we need two activity screens. One is our Main Acitivity and another one is our splash screen activity. Unluckily we don't have any pre-defined mechanism for this feature like in iOS. So, Lets Get Started.

Android Splash Screen Using Timer

Here we using timer for implement android splash screen activity.

implement android splash 
screen

Create a new File - (Implement android splash screen)

implement android splash screen

Choose an Correct API Version - (Implement android splash screen)

implement android splash screen

Template selection for our activity (Implement android splash screen)

implement android splash screen

Give a Name to our activity - Default is MainActivity (Implement android splash screen)
2. To create a Splash Screen we've to create a new activity from the file menu. Following is the procedure to create new activity. Just go to File -> New -> Activity -> Blank Activity. And then just go with next and finish to create a fresh activity.
implement android splash screen
Create Blank Activity - (Implement android splash screen)
implement android splash screen
Name to the second Activity as SplashScreen - (Implement android splash screen)
3. The next step is more important to make a screen as first in the app. Open your Manifest file and change your content_splash_screen as launcher actitvity.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidhotspot.splashscreen" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
</manifest>
4. When create a new activity, the android studio automaticaly creates two files under the res -> layout folder, and an activity java file. After confirm whether the above files are placed on their locations open content_splash_screen.xml to design our splash screen. And modify your content_splash_screen.xml like the file below. Copy and paste the below code into your splash_screen.xml.

content_splash_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgLogo">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="12dp"
android:textColor="#454545"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:text="www.androidhotspot.com"
android:id="@+id/textView" />
</RelativeLayout>
After adding the code go to Design tab in the content_splash_screen.xml and the output design should be look like this. If you don't have your own logo image just download it from here(Logo Image Link).

implement android splash screen

Expected design of the splashscreen.xml - (Implement android splash screen)
5. Completing the design part let's move to the brain part of the how to implement the Android splash screen. In this tutorial our main target is not the MainActivity.java instead we use the SplashScreen.java because we mention this is the launcher for the application.
The main concept in this How to implement Android Splash Screen application is slow down the showing process of the single activity in an application. For that we use postDelayed method from the Handler class. When you choose the handler it shows the two handler classes, one is normal Java handling class and another one is Android handler. From these two options we've decide for our how to implement the Android splash screen application Android Handler. It also automatically implements an method called run().

SplashScreen.java

package com.example.androidhotspot.splashscreen;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
public class SplashScreen extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 4000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME_OUT);
}
}
After complete the coding run the application from the menu bar, you will see the Splash screen for 4 seconds and then our MainActivity is launched.

implement android splash screen

In this How to implement Android Splash Screen lesson Splash Screen for the first four seconds of our app - (Implement android splash screen)
In this how to implement the Android splash screen tutorial we didn't change any codes in MainActivity.Java because we don't need to modify that for this stuff. If you want add something in MainActivity you can add in the .java file.

implement android splash screen

The home Screen of our App after the Splash Screen - (Implement android splash screen)

Leave a Reply