There is 2 ways (at least) to create a splash screen : The first is to create a splash activity displaying a layout and then transfert the user to the main activity. Here the SplashActivity.java :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class SplashActivity extends AppCompatActivity { private static int SPLASH_DURATION = 2000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_activity); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(SplashActivity.this, MainActivity.class); startActivity(intent); finish(); } },SPLASH_DURATION); } } |
Note : the splash screen is displayed during 2 seconds (2000 ms) before going to the main activity. You can tune the SPLASH_DURATION…