Android
Adding Splash Screen To Your Android App

Adding Splash Screen To Your Android App

“A splash screen in an android application is an activity consisting of a window containing an image or a logo and the current version of the app. A splash screen usually appears while an application is launching.

Splash screens are typically used by particularly large applications to notify the user that the program is in the process of loading. They provide feedback that a lengthy process is underway. Occasionally, a progress bar within the splash screen indicates the loading progress. A splash screen disappears when the application’s main window appears.

Splash screens typically serve to enhance the look and feel of an application, hence they are often visually appealing. They may also have animations, graphics, and sound. Many popular Android Apps such as Skype, Facebook, Adobe Reader, 500px, Dropbox etc.,  uses the splash screen to display their logo. Most Android Apps uses Android Splash Screen before launching application Activity.”




There are two scenarios in which splash screen is implemented.
1. Using Splash screen to showcase the logo of your app(uses a timer or sleep method).
2. Showing Splash screen while making network calls like,
• Downloading required images and data
• Fetching and parsing data and many more things…..

In this article, I’m going to explain the first scenario. In the first scenario, splash screen can be implemented by two methods.
METHOD 1: Set time to handler and call Handler().postDelayed , it will call run method of runnable after the set time and redirect to the main app screen.
METHOD 2: Create a thread and set time to sleep after that redirect to the main app screen.

 

I have made a separate activity for splash screen after which the main activity will be started. Now, let us discuss the whole implementation of splash screen in android studio step by step.

1. Create a new project in Android Studio by navigating to File -> New Project and fill required details. (I kept my main activity name as MainActivity.java).

2. To display a splash screen, we need a layout first of all. So let’s create a layout file for splash screen under  app ->  res -> layout  folder and selecting New -> Layout resource file . Give it any name. I named the layout file as activity_splash-screen.xml. This layout normally contains your app logo.

3. Now Open File Explorer in your Operating System and paste the image you want to use as a splash screen in Drawable Folder.(Generally located at C:\Users\UserName\ AndroidStudioProjects\ ProjectName\ app\ src\main\res\drawable) .

4. Now type the following code in Tab of activity_splash-screen.xml:

5. Splash screen is a separate activity which will be displayed first ahead of all other Activity. We create splash screen activity by creating a class. We create a new class by Selecting app -> java -> Your Package Name and right-clicking on your package and selecting New -> Java Class. Give it any name. Here, I gave it as SplashScreen.   Now Type the Following Code in SplashScreen.java activity:(Here I have provided code for both methods mentioned above, call Handler().postDelayed or creating a thread )

In METHOD 1, a variable named time_out is declared with timer value. Then set time to handler and call Handler().postDelayed , it will call run method of runnable after the set time and redirect to the main app screen.

In METHOD 2, we used methods of Thread class such as

– sleep(long time) – to make the thread sleep for some time (in milliseconds).

– start() – to start the thread.

sleep takes the time in milliseconds as its parameter(3000 => 3 seconds). Here we used this delay time as the time to display the splash screen activity.

After this delay time, MainActivity is started by the code written in finally{} block. Next, We need to define which activity to open after displaying Splash screen. This is done using the Intent(Context, Class) constructor of the Intent class.

6. Now to make your splash screen to work, you need to refer the SplashScreen Activity in Android Manifest. So open the Manifest file by clicking on app > Manifests > AndroidManifest.xml. Now we add a reference to the new activity we just created and change the Launcher Activity (Activity which Launches first) to  activity_splash-screen.xml by changing the code shown below:

After executing above code following activity will show as shown below,

Screenshot_2015-09-24-22-26-16

 

Note:

1. Above mentioned code is according to my package name and name conventions used by me.

2. The image displayed in the screenshot is not provided by me, so you have to find a replacement for it.

Share this Story

Related Posts

Leave a Reply

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

About Me


I am an enthusiastic technology geek, always on an endeavour to explore new areas of technology. At present, I am on an endeavour to explore the area of Machine Learning. At KnowMyWork I am constantly sharing my learning from my endeavors with people.

Facebook

Know My Work on Google Plus

Newsletter