What is Splash Screen
Splash screen is the screen that the user sees first when the application starts. This is an important screen where users can get a first impression of the application. The splash screen is the screen that appears when you open the app on your mobile device. Sometimes called the splash screen or home screen, it appears when the app loads immediately after you open it.
The Splash screens are ideal to keep better user experience while loading initial setup of the application when it is opened in the mobile device. When loading is finished the user will be taken to the applications functional screen where the user can complete the action.
Splach screen appears on the screen for very short time, some times the users might1 miss them. It is the one of the most vital element in your application as it is the first experience when the user open your application.
We can create Splash screen in two different ways, these two methods are common methods of creating the splash screen in Android.
One is Using Time Interval to show the splash screen. In this method a timer will be used to decide when to show the main screen of the application.
Timer method is the worst implementation idea since it result it Cold Start in the application. It is not suitable method for create a splash screen.
Second one is using a Launcher Theme to the application to launch the application and show the splash screen while the application is fetching the relavent data if any. And this method is the best one in all cases and gives a best user experience without any lagging on white screen when launching the application.
Using Timers for Splash Screen
Using timer in the activity to show the splash screen, we have to create an activity for splash screen. And in that activity onCreate()
method is created with a thread that display the splash screen UI for a certain seconds, lets say 2/3 seconds. After the timer done, it will take to the desired activity. The below code will help you to understand the implementation of this method.
This approach isn’t advised as it will rise to cold start in the application.
What is Cold Start?
A cold start refers to an app’s starting from scratch. This means that the app’s process has not been created by the system until then. Cold starts occur when you are launching the app for the first time since booting, or if the app was killed. Since there is no existing process up and running this is the slowest type of launch. Cold starts are usually the main focus when it comes to minimizing app launch time due to them taking the longest. – Instabug.com
www.instabug.com
As mentioned earlier, the purpose of the splash screen is to display a beautiful screen, while the application is processing the launch or fetching the content from the internet or from the Database. With above method, there will be additional load to the Splash Activity to create the splashlayout.
It will result in low start of the application, which gives a bad user experience to by displaying a blank black or white screen in the application.
So, to overcome this issue and improve the User experience and application load time, we have to use the second method, where a launch theme is created to load the splash screen instead of creating a layout for the activity.
Since, the Application theme
is instantiated before the layout is created, we can create a theme for splash screen, instead of regular layout. To do this we’ll set the drawable inside the theme that’ll contains the activity’s background and icons using the layer-list
.
Create a custom theme for the splash screen and set it the custom theme in Manifest for the splash screen activity. Please follow the below steps to create the custom theme.
Step 1
Create the background xml for the Splash Screen in drawable directory like drawables/bg_splashscreen.xml
this drawable is the image which displayed in the Splash Screen.
Step 2
Create the background onto where your app logo will be placed in drawable/bg_gradient.xml
depending on your application this background can be a gradient or any color.
Step 3
Create new style in the themes for the splash screen, in res/values/themes.xml
Step 4
Now create an empty activity for the splash screen named SplashScreenActivity
and set the style as the custom theme for it inside the AndroidManifest.xml
Step 5
Now set the target intent inside the SplashScreenActivity
, in my case I’m setting the target intent as LoginActivity.java
as given below.
Since, we are loading the splash screen from the manifest, there is no need to setContentView()
with any xml layout. If there is any need to show the splash screen for some time or want to fetch some content, you can use the timer to achive that. But fetching any content in main screen is recommanded approach.