Flash Screen with ProgressBar

Here we will create a simple app which displays a flash screen with a ProgressBar for 3 seconds before moving to MainActivity.

Step 1: Create a new project with name ProgressBar and package name com.apktutor.progressbar. Select File -> New -> New Project. Fill the forms and click “Finish” button.

Step 2: Open res -> layout -> xml (or) main.xml and add codes for layouts and widgets you want on main page.

<?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:gravity="center"
	android:orientation="vertical">

	<TextView
		android:layout_height="wrap_content"
		android:textAppearance="?android:attr/textAppearanceLarge"
		android:layout_width="wrap_content"
		android:text="You are on main page now"/>

</LinearLayout>

Step 3: Add a new layout flash.xml and add following codes. This code shows a ProgressBar of Large style.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:orientation="vertical"
	android:gravity="center_vertical|center_horizontal">

	<ProgressBar
		style="?android:attr/progressBarStyleLarge"
		android:layout_height="wrap_content"
		android:layout_width="wrap_content"/>

</LinearLayout>

Step 4: Open app -> java -> package and open MainActivity.java. Add following code in it. Here in onCreate we use Intent to move to FlashActivity.

package com.apktutor.progressbar;

import android.app.*;
import android.os.*;
import android.content.*;

public class MainActivity extends Activity 
{
	private Intent intent = new Intent();
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
		intent.setClass(getApplicationContext(), FlashActivity.class);
		startActivity(intent);
		
    }
}

Step 5: Create a new java page FlashActivity.java. Here we use a TimerTask, and finish Activity after 3 seconds.

package com.apktutor.progressbar;

import android.app.*;
import android.os.*;
import java.util.*;

public class FlashActivity extends Activity 
{
	
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.flash);
		
		Timer _timer = new Timer();
		TimerTask timer = new TimerTask() {
			@Override
			public void run() {
				finish();
			}
		};
		_timer.schedule(timer, 3000);
    }
}

Step 6: In AndroidManifest.xml, declare the FlashActivity.

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
		android:resizeableActivity = "true">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
		<activity
            android:name=".FlashActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

Output:
Now run the app. The flash screen with ProgressBar will show for 3 seconds before the main screen.