Wednesday 13 April 2016

How to implement Android Splash Screen

Splash Screens are upcoming trend to showcase you app logo and further information. Android officially does not have any builtin mechanism to show a splash screen as IOS do. Today we are gonna learn how to add a splash screen for you android app. 


Please follow the below steps:
  • Create your android project and rename your MainActivity to SplashScreen and finish building your project.
  • Add one more Activity to your project namely MainActivity .
  • Now simply copy and paste the below code to your SplashScreen.java class.
 import android.app.Activity;  
 import android.content.Intent;  
 import android.os.Bundle;  
 import android.os.Handler;  
 public class SplashScreen extends Activity {  
   // Splash screen timer  
   private static int SPLASH_TIME_OUT = 2500;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_splash);  
     new Handler().postDelayed(new Runnable() {  
         
       @Override  
       public void run() {  
         // This method will be triggered once the timer is over  
         // Start your app MainActivity  
         Intent i = new Intent(SplashScreen.this, MainActivity.class);  
         startActivity(i);  
         // close this activity  
         finish();  
       }  
     }, SPLASH_TIME_OUT);  
   }  
 }  

  • Now u may make changes to res ⇒ layout ⇒ activity_splashscreen.xml to meet your requirement.
That's all, now when ever you open your app a splash screen will be show for 2.5 seconds.


No comments:

Post a Comment