How To Make Splash Screen In Android Example Tutorial |Android App Development With AndroidCource

Sunday 17 June 2018

How To Make Splash Screen In Android Example Tutorial

Splash Screen in Android Example Tutorial

Create Splash Screen in Background Thread Processing to Process in Activity some time to display SplashScreen . And Close Screen to thread is Stopped and Main Screen Open.

Example Of Splash Screen

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".SplashActivity"
    android:background="@drawable/splashnew">

</RelativeLayout>

MainActivity.java

package com.example.com.mobileshopapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

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

        getSupportActionBar().hide();

        Thread thread = new Thread(){

            @Override
            public void run() {

                try {
                    sleep(5000);

                    startActivity(new Intent(SplashActivity.this,MainActivity.class));
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }
}

0 comments:

Post a Comment