Example : How to create a Splash Screen for an Android App/Activity using XML and Android Java.
				
					AndroidManifests.xml file 
------------------------------

[Set .SplashScreenActivity.xml file as Top in Activity tag with <intent-filter> --- </intent-filter> contents]


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

    <application android:allowbackup="true" android:dataextractionrules="@xml/data_extraction_rules" android:fullbackupcontent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round" android:supportsrtl="true" android:theme="@style/Theme.MyApplication" tools:targetapi="31">

        <activity android:name=".SplashScreenActivity" android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"></action>

                    <category android:name="android.intent.category.LAUNCHER"></category>
                </intent-filter>
        </activity>

        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"></action>

                <category android:name="android.intent.category.LAUNCHER"></category>
            </intent-filter>
        </activity>

    </application>

</manifest>



activity_splash_screen.xml
------------------------------

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" tools:context=".SplashScreenActivity">

    <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Splash Screen Appears ..." android:textsize="30dp" android:textcolor="@color/design_default_color_error" android:textstyle="bold"></textview>

</linearlayout>



SplashScreenActivity.java 
------------------------------

package com.rkm.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreenActivity extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        Intent x= new Intent(SplashScreenActivity.this, MainActivity.class);

        new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                startActivity(x);
                finish();
            }
        },4000);
    }


}

				
			
Categories: Android

0 Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.