sohaib rahman sohaib rahman - 4 days ago 8
Android Question

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 that how 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 the button.

Answer
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);
Comments