IntentUtils { public static void restartApp(Context context) { Intent intent = new Intent(context, SplashscreenActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); } private  IntentUtils(); static void startEmailIntent(Context context, String chooserTitle, String recipient, String subject); static void startSiteIntent(Context context, String website); static void startGooglePlayIntent(Context context); static void restartApp(Context context);  }
@Test public void should_restart_splash_screen_clearing_stack() { IntentUtils.restartApp(activity); ShadowActivity shadowActivity = Shadows.shadowOf(activity); Intent intent = shadowActivity.getNextStartedActivity(); assertThat(intent.getComponent().getClassName()).isEqualTo(SplashscreenActivity.class.getName()); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TASK).isEqualTo(Intent.FLAG_ACTIVITY_CLEAR_TASK); }