First take a class which extends Activity. Then take a Thread object and start it inside the oncreate method, call wait method and give a waiting time as a parameter to it.After that make a new Intent and start it as a activity. Below code is self-descriptive.
public class MySplashScreen extends Activity {
// splash page displaying time
protected int _splashTime = 4000;
// take a thread object.
private Thread splashTread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
// times to show the splash page
wait(_splashTime);
}
} catch (InterruptedException e) {
} finally {
// go next activity after
// finish the thread.
nextActivity();
}
}
};
// start the thread
splashTread.start();
}
// if user touch the splash screen then
// immediately go to next screen.
// No more waiting :D
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized (splashTread) {
splashTread.notifyAll();
}
}
return true;
}
// go next activity
public void nextActivity() {
Intent Start = new Intent(this, FirstActivity.class);
startActivity(Start);
finish();
}
}
Bonus: If user touch the splash screen then immediately go to next screen.No more waiting :D :D
Download code: Click here.