Search code examples
androidtimersplash-screen

How to display an activity automatically after 5 seconds?


In my application I have created a splash screen type of thing in Android. It should remain for 5 seconds.

My problem is how do I display another activity automatically after 5 secs?

The splash screen doesn't have a button, rather it should display another activity automatically after 5 seconds without the click of a button.


Solution

  • new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    final Intent mainIntent = new Intent(LaunchActivity.this, HomeActivity.class);
                    LaunchActivity.this.startActivity(mainIntent);
                    LaunchActivity.this.finish();
                }
            }, 5000);