I need a splash screen for my application. Tried creating an activity having the image for my splash screen; and tried using for loop and the Timer class for introducing a t
Try this,
protected int _splashTime = 15000;
private Handler handler;
private Runnable runnable;
private Context context;
@Override
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
setContentView(R.layout.splash);
final SplashScreen sPlashScreen = this;
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
try {
handler.removeCallbacks(runnable);
handler.postDelayed(runnable, _splashTime);
}
finally {
finish();
//start a new activity
//mtdCheckLicense();
Intent main = new Intent();
main.setClass(sPlashScreen, YourMainActivity.class);
startActivity(main);
handler.removeCallbacks(runnable);
}
}
};
handler.postDelayed(runnable, 2000);
}
It will splash for some time and launch the main activity. In this code the splash screen wait for 2Seconds and then launches the main activity.