Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display an activity automatically after 5 seconds

Tags:

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.

like image 371
sohaib rahman Avatar asked Jun 10 '11 08:06

sohaib rahman


People also ask

How do you call a function after an android time?

You can use this for Simplest Solution: new Handler(). postDelayed(new Runnable() { @Override public void run() { //Write your code here } }, 5000); //Timer is in ms here.

How do I start the same activity again on android?

If you just want to reload the activity, for whatever reason, you can use this. recreate(); where this is the Activity. This is never a good practice. Instead you should startActivity() for the same activity and call finish() in the current one.


1 Answers

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);
like image 187
kzotin Avatar answered Oct 06 '22 22:10

kzotin