Showing Splash Screen in Full Screen Mode using CountDownTimer in Android

September 4, 2012
By

In this article, we will create an Android application containing a splash screen. This splash screen will be run in full screen mode. It is resistant to screen rotation while splash screen is up. This splash screen is implemented using a simple Android API called CountDownTimer.

This application is developed in Eclipse ( 4.2.0) with ADT plugin ( 20.0.3) and Android SDK ( R20.0.3)


1. Create a new Android application project namely “SplashScreenDemo”

Create new Android Application Project namely "SplashScreenDemo"

Figure 1 : Create new Android Application Project namely "SplashScreenDemo"


2. Design application launcher icon

Design application launcher icon

Figure 2 : Design application launcher icon


3. Create a blank activity to define MainActivity class

Create a blank activity in this project

Figure 3 : Create a blank activity in this project


4. Enter MainActivity details

Enter MainActivity details

Figure 4 : Enter MainActivity details


5. Delete Android’s support library from the project, if exists

By default Eclipse ( 4.2.0) adds Android Support Library to¬† Android application project. For this application, we don’t need to use this support library. So the library file libs/android-support-v4.jar may be removed manually via ProjectExplorer by simply right click on the file and then clicking the menu item “delete”.


6. Update the file res/values/strings.xml


<resources>
    <string name="app_name">SplashScreenDemo</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="title_activity_demo">Splash Screen Demo</string>
    <string name="splash_message">Welcome to Splash Screen Demo</string>
    <string name="demo_message">This is Demo Activity</string>
</resources>


7. Update the layout in the file res/layout/activity_main.xml

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:contentDescription="Logo" />

    <TextView
        android:id="@+id/tv_splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/splash_message"
        android:textSize="20dp"
        tools:context=".MainActivity" />

    <ProgressBar
        android:id="@+id/pb_splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dp" />

</LinearLayout>

8. Create a new layout for the class DemoActivity in the file res/layout/activity_demo.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/demo_message" />

</RelativeLayout>


9. Create an activity class namely DemoActivity in the file src/in/wptrafficanalyzer/splashscreendemo/DemoActivity.java


package in.wptrafficanalyzer.splashscreendemo;
import android.app.Activity;
import android.os.Bundle;

public class DemoActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
    }
}


10. Update the class MainActivity in the file src/in/wptrafficanalyzer/splashscreendemo/MainActivity.java


package in.wptrafficanalyzer.splashscreendemo;

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

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /** Hiding Title bar of this activity screen */
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        /** Making this activity, full screen */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        /** Sets a layout for this activity */
        setContentView(R.layout.activity_main);

        /** Creates a count down timer, which will be expired after 5000 milliseconds */
        new CountDownTimer(5000,1000) {

            /** This method will be invoked on finishing or expiring the timer */
            @Override
            public void onFinish() {
                /** Creates an intent to start new activity */
                Intent intent = new Intent(getBaseContext(), DemoActivity.class);

                /** Creates a new activity, on finishing this timer */
                startActivity(intent);

                /** Close this activity screen */
                finish();
            }

            /** This method will be invoked in every 1000 milli seconds until
            * this timer is expired.Because we specified 1000 as tick time
            * while creating this CountDownTimer
            */
            @Override
            public void onTick(long millisUntilFinished) {
            }
        }.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}


11. Update the file AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.wptrafficanalyzer.splashscreendemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:screenOrientation="nosensor" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".DemoActivity"
            android:label="@string/title_activity_demo" >
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>


12. Screenshot of the application

Screenshot of the SplashScreen in Action

Figure 5 : Screenshot of the SplashScreen in Action


13. Download


14. Reference

http://developer.android.com/guide/index.html


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , , , , ,

8 Responses to Showing Splash Screen in Full Screen Mode using CountDownTimer in Android

  1. Android on September 10, 2012 at 11:15 pm

    Nice tutorial but there’s a problem with the TextView.the id is also passed into the ImageView using the android:layout_above and android:layout_below and my eclipse is complaining saying that there are no resources for the three.how do i solve that problem

  2. Android on September 10, 2012 at 11:29 pm

    secondly,when i run the app,there are errors pointing in that direction.i deleted the id for the textview with the android:layout_above and below for the imageview but wen i ran it,the screen was black n blank.help

    • george on September 11, 2012 at 9:10 am

      Thank you for reporting the issue.
      The issue may be easily fixed by changing the layout(activity_main.xml) from RelativeLayout to LinearLayout.

  3. Android on September 11, 2012 at 3:22 pm

    i guss the problem i had was with my Eclipse.i downloaded a new one and tried it again word for word as u wrote n i had no errors but on run,the app forcefully closes.in the Mainfest.xml file,thr was an error saying u can’t also write an intent for the DemoActivity class because it requires no permission.so i removed it n ran it again.same time pls where did i go wrong.this is my manifest file

  4. Android on September 11, 2012 at 3:42 pm

    my manifest.xml file is written below

  5. Android on September 11, 2012 at 3:59 pm

    it works!!!!!!!!.

    but y doesn’t it work on android 3.0? i tried testing it on it just to see how it looks like because android 3.0 has a tablet view.so i tried it on android 4.0 n it worked perfectly.thanks man n forgive my questions am just new to this

    • george on September 11, 2012 at 4:24 pm

      That is nice.
      Make it up in 3.0 also !!!

  6. sarath on May 28, 2013 at 12:21 pm

    i need to wait until the latitude>0.0 and longitude>0.0 how can i apply this code in it?

    thank you

Leave a Reply to Android Cancel reply

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

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner