Starting an activity after 1000ms from a splash screen with Runnable and Handler().postDelayed I have implemented a splash screen which is the main activity of my Android app. This splash screen shows an image, and after 1000ms there is an animation to show another activity's layout.

The code I've written is the following:

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        startTheTransitionAfterTheSplashScreen();
    }

    private void startTheTransitionAfterTheSplashScreen() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intentSplashScreenToActivityJustAfterSplashScreen = new Intent(SplashScreen.this, ActivityJustAfterSplashScreen.class);
                startActivity(intentSplashScreenToActivityJustAfterSplashScreen);
                overridePendingTransition(R.anim.animation_enter_activity, R.anim.animation_leave_activity);
                finish();
            }
        }, 1000);
    }
}


And for the animations:

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"&gt;
    &lt;translate
        android:fromXDelta="100%" android:toXDelta="0%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="500" /&gt;
&lt;/set&gt;

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"&gt;
    &lt;translate
        android:fromXDelta="0%" android:toXDelta="-100%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="500" /&gt;
&lt;/set&gt;


Question

What I would want to ask is especially about the startTheTransitionAfterTheSplashScreen (I think the animations are correctly written): should I actually use a Runnable with a Handler to delay the transition? (in other words: is it suitable for this splash screen, or is there a better way to do that?)

Edit

Implementing K.H.'s answer:

public class SplashScreen extends AppCompatActivity {

    private Handler the_transition_handler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
    }

    @Override
    protected void onStart() {
        super.onStart();
        startTheTransitionAfterTheSplashScreen();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        the_transition_handler.removeCallbacksAndMessages(null);
    }

    private void startTheTransitionAfterTheSplashScreen() {
        the_transition_handler = new Handler();
        the_transition_handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                final Intent intentSplashScreenToActivityJustAfterSplashScreen = new Intent(SplashScreen.this, ActivityJustAfterSplashScreen.class);
                startActivity(intentSplashScreenToActivityJustAfterSplashScreen);
                overridePendingTransition(R.anim.animation_enter_activity, R.anim.animation_leave_activity);
                finish();
            }
        }, 1000);
    }
}
I don't like name startTheTransitionAfterTheSplashScreen. Too long, you are already in SplashScreen. Maybe startTransition or startTransitionafter1second.

Using handler is fine, but what if user manages to change orientation during that 1 second? Activity gets destroyed and recreated. Now you have 2 active handlers and I expect ActivityJustAfterSplashScreen will be called 2 times.

I suggest keeping reference to handler so that you can cancel in onDestroy - handler.removeCallbacksAndMessages(null).