How to create android splash screen
In this tutorial I’m going to show you how to easily create an android splash screen in your application.
The whole idea of this sample implementation is to start and display an activity for a certain amount of time and then start new activity. Our activity code is listed below.
SplashActivity.java
package com.itcuties.tutorial.android; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.view.WindowManager; public class SplashActivity extends Activity { private static String TAG = SplashActivity.class.getName(); private static long SLEEP_TIME = 5; // Sleep for some time @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar setContentView(R.layout.splash); // Start timer and launch main activity IntentLauncher launcher = new IntentLauncher(); launcher.start(); } private class IntentLauncher extends Thread { @Override /** * Sleep for some time and than start new activity. */ public void run() { try { // Sleeping Thread.sleep(SLEEP_TIME*1000); } catch (Exception e) { Log.e(TAG, e.getMessage()); } // Start main activity Intent intent = new Intent(SplashActivity.this, MainActivity.class); SplashActivity.this.startActivity(intent); SplashActivity.this.finish(); } } }
As you see the implementation is really simple. We have a private class which is responsible for waiting some amount of time and launching a main activity in a new thread. We construct and start this thread at the end of onCreate method when a view has been set.
Remember that SplashActivity is the starting activity of our application so don’t forget to set android.intent.category.LAUNCHER category in Your AndroidManifest.xml file. Our sample manifest file code looks like this.
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itcuties.tutorial.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> </activity> </application> </manifest>
Download Eclipse project containing this samples here.
thanks, works great ,good tutorial.
thanx its working.
how to use webservices from other server
hi,
I have tried xml parsing code from your tutorial but its showing som error in ——————->>>
public void onItemClick(AdapterView parent, View view, int pos, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(listItems.get(pos).getLink())); // error as method getLink() is undefined for the type Object
activity.startActivity(i);
}
please tell me the mistake ..
Hi,
Our visitor Duke has solved this problem :)
Take a look here: http://www.itcuties.com/android/how-to-write-android-rss-parser/#comment-896
itcuties
Another easy way using Timer class
I’m having a small issue with your code – more than likely on my end.
The splash screen shows and goes on to my main screen as per the tutorial
but the “Loading…” text does not show on the splash screen.
I’ve tried using a background image as well as a button on the splash screen but none appear only
a white blank screen. No errors appear in the code in compiling or running.
The background that im trying to use on the splash screen appears perfectly on the main screen
Any help would be much appreciated
Hi Dave,
can you send us your code to team@itcuties.com? We can then see what’s going on and try to help you :)
Have a nice day,
itcuties
Can we make the splash welcome screen only to show up when the customer do a FRESH install? Instead of showing up every time when the app is being updated?
You should store information about first program run in the database or a file. Every time the app is started you need to check is that information stored and if is not than display the welcome screen. We have a tutorial on how to store data in SQLite database. Check it out – http://www.itcuties.com/android/sqlite-example-the-todo-application/.
nice tutorial but why new class require we can create new thread and do same thing in it ..
Hello, can you be more specific?
Hello!How paste .gif image for animation?Just static picture or text not that what I need.
Thanks in advance.
Animated gifs won’t work in Android. You need to use the
android.graphics.Movie
class. Check out this page – http://stackoverflow.com/questions/3660209/display-animated-gif.My app keeps force closing. Any help?
Is it possible to make a double splash screen in the app??
A splash screen after a new splash screen, if yes then how?
Great work IT-cuties, your work is as cute as yourselves.