Welcome to Our Website

Android Splash screen Implementing, correct way.

native_android_splash

Every mobile developer know that Splash screen is the screen appears when you open an app on your mobile. They set the stage for your application, while allowing time for the app engine to load and your app to initialize. 

Generally we try to add Start up activity as splash screen using with the help of timer. we create a splash activity and create a thread in onCreate() for shows up for 2/3 seconds, then go to our desired activity. 

public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, 3000);
}
}

Also you can execute some code (firebase initialization, dynamic link etc.) at this point but this is NOT the correct way.

The Disadvantage of above method is it’ll give rise to slow starts to the application which is bad for the user experience (wherein a blank black/white screen appears).

The Correct way

The cold start appears since the application takes time to load the layout file of the Splash Activity. So instead of creating the layout, we’ll use the power of the application theme to create our initial layout.

Application theme is instantiated before the layout is created. We’ll set a drawable inside the theme that’ll comprise the Activity’s background and an icon using layer-list as shown below. So, we will set a custom theme in Manifest for our splash activity. To create the theme for the splash screen, follow the below process.

Step 1

Create the gradient onto which your app logo will be placed in drawable/bg_gradient.xml, background can be a gradient or any colour depending on your app.



Step 2

Create Background for Splash Screen in drawable/splash_background.xml, the bitmap is the image we want to show.






Step 3

Create Style for Splash Screen in res/values/themes.xml


Step 4

Use this theme to set in application while application starts loading through AndroidManifest.xml

Using the theme and removing the layout from the SplashScreenActivity is the correct way to create a splash screen