
What is splash screen?
A graphical element or screen appears for few seconds before an application launch.
When we should use Splash screen?
- We can use to show the welcome message when application is launching first time.
- While loading the data from remote system or data base , usually it takes time that time we can show the splash screen(Loading … screen)
- When we need to perform any operation and that required time to execute , we can show the splash screen.
Steps
- Create one Activity1 and XML file
- Design the XML file and put the welcome message
- Crete Activity2 and XML file.
- Start the Activity1
- Start a Thread in Activity1 and sleep for 5 seconds
- Start Activity2 from the Thread
There is nothing called readymade splash screen in Android . we can achieve that using above steps.
In a single line, start Activity1 wait for 5 sec then start Activity2.
So user will feel that first screen is splash screen.
In this I am not going to show the steps how to make application using android in android studio.
If you don’t know how to make application in android , please read the hello world in android
Live Demo
I have created an android application with two Activities
Activity1.java
package com.splashscreen; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class Activity1 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity1); Thread t = new Thread(){ public void run(){ try{ sleep(5000); } catch(Exception e){ e.printStackTrace(); } finally { startActivity(new Intent(new Intent(getApplicationContext(), Activity2.class))); finish(); } } }; t.start(); } }
Activity2.java
package com.splashscreen; import android.app.Activity; import android.os.Bundle; public class Activity2 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity2); } }

activity_activity1.xml
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Activity1" android:background="@color/highlighted_text_material_dark"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Welcome to JavaAnt..." android:id="@+id/textView2" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="172dp" /> </RelativeLayout>
activity_activity2.xml
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.splashscreen.Activity2"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="This is Second Screen" android:id="@+id/textView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="148dp" /> </RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.splashscreen" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".Activity1" 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=".Activity2" android:label="@string/title_activity_activity2" > </activity> </application> </manifest>
Hope it will help you.
Leave a Reply