Create a class called: Splash then
paste this code into the flowing class
change the replace your main class by ".Splash" (the name of class we just created) then declare a new activity with the name of de fault class you just created
public class Splash extends Activity
{
boolean flag = false;
Runnable runnable;
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
runnable = new Runnable() {
@Override
public void run() {
if (!flag) {
final Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}
};
handler = new Handler();
handler.postDelayed(runnable, 5000);
}
@Override
protected void onPause() {
super.onPause();
flag = true;
handler.removeCallbacks(runnable);
}
@Override
protected void onRestart() {
super.onRestart();
flag = false;
handler.postDelayed(runnable, 1-1);
}
}
change the replace your main class by ".Splash" (the name of class we just created) then declare a new activity with the name of de fault class you just created
finally create your activity_splash layout in the layout folder