Opening screen in Android

Opening Screen in Android

An opening screen in Android is the first screen that appears when an application is launched. It is also called a Splash Screen. This screen is displayed for a few seconds before the main application screen opens. It usually shows the application logo, name, or a loading message.

The main purpose of an opening screen is to give a good first impression to the user and to show that the application is loading. During this time, the application can also perform some background tasks such as loading data or initializing resources.

To create an opening screen in Android, developers usually create a separate activity that appears first when the application starts. After a short delay, this activity automatically opens the main activity of the application.

First, a layout file is created for the opening screen. This layout normally contains an image or text representing the application logo or title.

Example layout file activity_splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/logo" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My Application"
        android:textSize="24sp"
        android:layout_marginTop="20dp"/>
</LinearLayout>

Next, a SplashActivity class is created. This activity will display the opening screen for a few seconds and then move to the main activity.

Example SplashActivity.java

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

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

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 3000); // 3 seconds delay
    }
}

In this program, the splash screen is displayed for 3 seconds using a Handler. After the delay, the application automatically opens the MainActivity.

Finally, the AndroidManifest.xml file must be modified so that the splash activity starts first when the application is launched.

Example AndroidManifest.xml

<application ... >

    <activity android:name=".MainActivity" />

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

</application>

Here, the SplashActivity is set as the launcher activity, which means it will open first when the user starts the application.

In simple terms, an opening screen in Android is the first screen shown when the app starts, and it is created by designing a splash layout, creating a splash activity, and setting that activity as the launcher in the manifest file.