Splash Screen Android Example Code

In this post you can learn on how to set up a splash screen in android before entering the home screen with a few seconds timeout which gives a professional rich UI design user experience.

HomeScreen Activity Java File

public class HomeScreen extends Activity {
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homescreen); 
         
    } 
     
    @Override
    protected void onDestroy() {
         
        super.onDestroy();
         
    }
}


Splashscreen activity Java file

public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        
         
//Sleep for 5 seconds
        Thread background = new Thread() {
            public void run() {
                 
                try {
                    sleep(5000);
                     
                    Intent i=new Intent(getBaseContext(),HomeScreen.class);
                    startActivity(i);
                     
                    //remove the activity
                    finish();
                     
                } catch (Exception e) {
                 
                }
            }
        };
         
        // starting the thread
        background.start();
             
    }
     
    @Override
    protected void onDestroy() {
       
        super.onDestroy();
         
    }
}

No comments:

Post a Comment

My Profile