Splash screen is a little unusable object in Android: it can not be loaded as soon as possible for hiding the delay of main activity starting. There are two reasons to use it: advertising and network operations.
Implementation as dialog makes jump without delay from splash screen to main UI of activity.
public class SplashDialog extends Dialog {
ImageView splashscreen;
SplashLoader loader;
int splashTime = 4000;
public SplashDialog(Context context, int theme) {
super(context, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
setCancelable(false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
cancel();
}
}, splashTime);
}
}
Layout:
And start:
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getCategories() != null && getIntent().getCategories().contains("android.intent.category.LAUNCHER")) {
showSplashScreen();
}
}
protected Dialog splashDialog;
protected void showSplashScreen() {
splashDialog = new SplashDialog(this, R.style.SplashScreen);
splashDialog.show();
}
...
}