Your needs is callign Splash Screen. Here is my splash screen code.
Just add new activity and set application for opening this activity.
public class SplashActivity extends DeviceInfoAbstractActivity {
@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.activity_splash);
passScreen();
}
private void passScreen() {
new CountDownTimer(1000, 2000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
Intent intent = RDAIntentHelpers.getClearCacheIntent();
intent.setClass(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
}.start();
}
@Override
public void onBackPressed() {
//no exit
}
}
and this my getClearCacheIntent() method
public static Intent getClearCacheIntent() {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
return intent;
}
after these, your splash screen stays on screen for 2 seconds. Do whatever you want =)
Handler
instead ofTimerTask
. – Hildredhildreth