Translate To Your Own Langauge

Splash screen in Android using Thread

Splash Screen is one of the most important topic in Android app Development. In almost every app, we see a screen for a short time and then actual Home screen is displayed. The purpose of this screen is to display logo of our app or any advert in our app. In this tutorial, I will show you the actual implementation of "Splash screen in Android using Thread". Before going in detail, one should know the use of Thread.
Definition: A thread is a single sequential flow of control within a program.
Now you have a rough idea about what is thread. Now we will use this concept to implement Splash screen in Android using Thread. For this, you need two XML files and Two .java files. Layout Doesn't matter in this tutorial because we are dealing with code in this example but still i am providing the xml code for you.
Follow these steps:

1. Make First xml file say Activity_main.xml. Copy and paste the following code into your xml file.

Activity_main.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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Welcome to AT4U app"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="68dp"
        android:src="@drawable/at4u" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="androidtutorial4u.blogspot.in" />

</RelativeLayout>

2. Now make the Second XML file which will be displayed after some time.

second.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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Now you are on second screen after splash."
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


3. Now all done with UI. Now you have to take care of coding phase which is more required. Now add two java files into the src folder. One file will be given already when you created the project.

mainActivity.java
package com.example.splashscreen;

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

public class MainActivity extends Activity {
       Thread th;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        th=new Thread(new Runnable() {
                    
                     @Override
                     public void run() {
                           // TODO Auto-generated method stub
                           try {
                                  Thread.sleep(3000);
                                  Intent it=new Intent(MainActivity.this,second.class);
                                  startActivity(it);
                                 
                                 
                           } catch (Exception e) {
                                  // TODO: handle exception
                           }
                          
                     }
              });
       
        th.start();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}


second.java
package com.example.splashscreen;

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

public class second extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              // TODO Auto-generated method stub
              super.onCreate(savedInstanceState);
              setContentView(R.layout.second);
       }
      

}

Now your project is ready. Download full source code.

23 Responses to “Splash screen in Android using Thread”

patel said...
11 July 2014 at 03:13

I am new in android. Its really beneficial for me. thanks sir


Unknown said...
6 September 2018 at 03:32

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…

Java Training in Pune


nivatha said...
13 September 2018 at 07:43

Appreciating the persistence you put into your blog and detailed information you provide

Data Science training in marathahalli
Data Science training in btm
Data Science training in rajaji nagar
Data Science training in chennai
Data Science training in electronic city
Data Science training in USA
Data science training in pune
Data science training in kalyan nagar




ragul ragul said...
21 September 2018 at 21:48

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
DevOps online Training


Unknown said...
3 October 2018 at 02:02

Well researched article and I appreciate this. The blog is subscribed and will see new topics soon.
Blueprism training in Pune

Blueprism training in Chennai


Unknown said...
6 October 2018 at 00:00

I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

angularjs Training in bangalore

angularjs Training in bangalore


Unknown said...
6 October 2018 at 00:00

I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

angularjs Training in bangalore

angularjs Training in bangalore


Limm Hyayng Phyo said...
9 October 2018 at 02:34

if back key click,it return reach activity_xml.please give me solution for this error.


tech bosa said...
10 February 2020 at 19:39

I really like looking through an blog article that can make people think. Also, many thanks for allowing for me to comment!


Maridev said...
29 September 2021 at 00:21

Grab the Digital Marketing Training in Chennai from Infycle Technologies, the best software training institute, and Placement center in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Cyber Security, Big Data, Java, Hadoop, Selenium, Android, and iOS Development, DevOps, Oracle etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.


Maridev said...
30 November 2021 at 05:02

If you are dreaming of an IT job !!! Then AWS Course in Chennai!!Is the best choice for you. Yes, what you heard is Right Infycle offering you an AWS course for an Affordable price with experienced trainees, Practical Classes, Flexible timing, and more.


Krystal345 said...
27 September 2023 at 10:24

https://bayanlarsitesi.com/
Ordu
Kocaeli
Düzce
Osmaniye

RCD88


Itır5 said...
30 September 2023 at 22:10

Adana
Erzurum
Sinop
istanbul
Düzce
2M4G


TimeStormPilot404 said...
3 October 2023 at 15:22

amasya
sinop
çorum
sakarya
van
08DB


ElectricByteGlider666 said...
3 October 2023 at 20:36

ankara
sakarya
tekirdağ
kastamonu
amasya
CV63C


0685ERaul1C40C said...
6 November 2023 at 16:09

88739
Yalova Parça Eşya Taşıma
Düzce Parça Eşya Taşıma
Kırşehir Lojistik
Sinop Lojistik
Van Lojistik


3128BLaylahC42A8 said...
6 November 2023 at 21:31

D2229
Bilecik Parça Eşya Taşıma
Niğde Evden Eve Nakliyat
İstanbul Parça Eşya Taşıma
Bilecik Evden Eve Nakliyat
Erzincan Evden Eve Nakliyat


9DF9DKenzie47090 said...
9 November 2023 at 20:33

0EE03
Ağrı Şehirler Arası Nakliyat
Ünye Evden Eve Nakliyat
Bayburt Şehir İçi Nakliyat
Adana Lojistik
Etlik Boya Ustası
Mardin Lojistik
Kırşehir Şehir İçi Nakliyat
Yobit Güvenilir mi
Denizli Evden Eve Nakliyat


ABDC5Alvaro30EFF said...
8 December 2023 at 04:53

94CE9
binance komisyon indirimi %20


6FD1DRoy53ED6 said...
25 December 2023 at 02:25

0E853
erzurum mobil sohbet et
Çanakkale Görüntülü Sohbet Kızlarla
çorum rastgele görüntülü sohbet uygulaması
batman sesli sohbet sitesi
yozgat sesli sohbet uygulamaları
Karaman Görüntülü Sohbet Kızlarla
Afyon Ücretsiz Sohbet Odaları
Trabzon Yabancı Görüntülü Sohbet
ağrı chat sohbet


B698CKylanA4E9C said...
5 January 2024 at 14:03

0B79C
canlı sohbet siteleri
Düzce Mobil Sohbet Et
telefonda kadınlarla sohbet
denizli en iyi ücretsiz sohbet siteleri
Bolu Ücretsiz Sohbet Sitesi
bartın ücretsiz sohbet
manisa rastgele sohbet
rastgele sohbet uygulaması
mobil sohbet odaları


D3986Philip37D1B said...
10 February 2024 at 03:41

6AE99
defillama
sushiswap
thorchain
layerzero
uwulend finance
zkswap
phantom wallet
uniswap
pudgy penguins


7EAFAEzekiel98180 said...
7 March 2024 at 05:19

32491
Enez
Pınarhisar
Sungurlu
Dazkırı
Elmadağ
Çanakçı
Altunhisar
Karamanlı
Pasinler


Post a Comment

Comment your feedback for the post. You can also ask your queries regarding android.

Blogger Widgets
All Rights Reserved Android Tutorials | Designed by: Deepak Anand