LOGO1_03

Android Splash Screen Example

A splash screen usually appears when a application is launching.It contain an image,a logo and the current version of the software.  A splash screen is an introduction page or starting screen of an application and it automatically call home page of application after some time duration.Every stander application contain an splash screen, so we need to learn how can we make a splash screen in android.Need two Activity class here those are below.          

  1.           SplashActivity.java
  2.           SecondActivity.java          

             You need to run a Thread to do this task, lets check code in SplashActivity.java. in this activity class start a Thread named "splash_thread" this activity containing an xml layout name "activity_splash.xml" you can customized this screen.need to declare the duration of Splash Screen as done in "splash_time",you can change as per your requirements.

Now have a look at source code

 1  SplashActivity.java

package com.androidfromhome.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends Activity {
    //set duration of splash
    final int splash_time =3000;
    private Thread splash_thread;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

         splash_thread = new Thread()
        {
            
        int interrupt_time = 0;

           public void run() 
            {
                 try 
        {
    super.run();
     while (interrupt_time < splash_time) 
    {
         sleep(100);
    interrupt_time += 100;
    }
    } 
                catch (Exception e) 
                {
                      
                 }
               
    finally{
                            //intent Calling , it's call another activity.
    startActivity(new Intent(SplashActivity.this,
        SecondActivity.class));
                            finish();
                            }
                   }
        };      
        splash_thread.start();

    }

}



2.  SecondActivity.java  


package com.androidfromhome.splash;

import android.app.Activity;
import android.os.Bundle;

public class SecondActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_activity);
//do your task
    }

    

}

Now source code of xml files.

1. activity_splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#A758AB"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.androidfromhome.splash.SplashActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Splash Screen"
        android:textColor="#ffffff"
        android:textSize="24dp"
        android:textStyle="bold" />

</LinearLayout>


2. second_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#343434"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="10dp"
        android:text="Android From Home"
        android:textColor="#ffffff"
        android:textSize="18dp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="#222222"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Second Screen"
            android:textColor="#ffffff"
            android:textSize="18dp"
            android:textStyle="bold" />

    </LinearLayout>

</LinearLayout>


Download Source Code

 

Leave a Reply

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

Get Widget