在Welcome Activity 的onCreate的方法中插入如下代码
new Handler().postDelayed(new Runnable(){ public void run(){ if(isLogined()){ //jump to main activity Intent intent = new Intent(WelcomeActivity.this,UserActivity.class); intent.putExtra(UserConfig.KEY_TOKEN, UserConfig.getCachedToken(WelcomeActivity.this)); startActivity(intent); }else{ //jump to login activity startActivity(new Intent(WelcomeActivity.this,LoginActivity.class)); } finish(); } }, 2900);//3 seconds later jump to main activity
与第一种的机制几乎一样
new Timer().schedule(new TimerTask(){ @Override public void run() { // TODO Auto-generated method stub if(isLogined()){ //jump to main activity Intent intent = new Intent(WelcomeActivity.this,UserActivity.class); intent.putExtra(UserConfig.KEY_TOKEN, UserConfig.getCachedToken(WelcomeActivity.this)); startActivity(intent); }else{ //jump to login activity startActivity(new Intent(WelcomeActivity.this,LoginActivity.class)); } finish(); } }, 2900);
Animation anim = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); anim.setDuration(3000);//last 3 seconds anim.setFillAfter(true);//hold the finished state anim.setAnimationListener(new AnimationListener(){ @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub if(isLogined()){ //jump to main activity Intent intent = new Intent(WelcomeActivity.this,UserActivity.class); intent.putExtra(UserConfig.KEY_TOKEN, UserConfig.getCachedToken(WelcomeActivity.this)); startActivity(intent); }else{ //jump to login activity startActivity(new Intent(WelcomeActivity.this,LoginActivity.class)); } finish(); } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } }); findViewById(R.id.logo).setAnimation(anim);