Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to create a Splash Screen in Android?

$
0
0
  1. packagecom.livrona.apps.justsikh.activity;
  2.  
  3. importandroid.app.Activity;
  4. importandroid.content.Intent;
  5. importandroid.os.Bundle;
  6.  
  7. importcom.livrona.andriod.commons.utils.Log;
  8. importcom.livrona.apps.justsikh.R;
  9.  
  10.  
  11. publicclass SplashScreen extends Activity {
  12.  
  13.         protectedboolean _active =true;
  14.         protectedint _splashTime =2000;// time to display the splash screen in ms
  15.        
  16.          @Override
  17.             publicvoid onCreate(Bundle savedInstanceState){
  18.                  
  19.                         Log.d("in : onCreate(..)");
  20.                 super.onCreate(savedInstanceState);
  21.                 setContentView(R.layout.splash_screen);
  22.                
  23.                
  24.              // thread for displaying the SplashScreen
  25.                     Thread splashTread =newThread(){
  26.                         @Override
  27.                         publicvoid run(){
  28.                             try{
  29.                                 int waited =0;
  30.                                 while(_active &&(waited < _splashTime)){
  31.                                     sleep(100);
  32.                                     if(_active){
  33.                                         waited +=100;
  34.                                     }
  35.                                 }
  36.                             }catch(InterruptedException e){
  37.                                 // do nothing
  38.                             }finally{
  39.                                 finish();
  40.                              // create the splash screen
  41.                                 Log.d("in : start the Home Screen Activity(..)");
  42.                                         // create the splash screen
  43.                                         Intent intent =new Intent(SplashScreen.this, HomeScreen.class);
  44.                                         intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
  45.                                         SplashScreen.this.startActivity(intent);
  46.                                        
  47.                             }
  48.                         }
  49.                     };
  50.                     splashTread.start();
  51.  
  52.                    
  53.                
  54.             }
  55. }

Viewing all articles
Browse latest Browse all 178

Trending Articles