Handling Animation Life Cycle Events

Now that you are happy with your animations, you just need to make QuizSplashActivity transition to QuizMenuActivity when the animations are complete. To do this, you create a new Intent control to launch the QuizMenuActivity class and call the startActivity() method. You should also call the finish() method of QuizSplashActivity because you do not want to keep this activity on the stack (that is, you do not want the Back button to return to this screen).

Of your animations, the fade_in2 animation takes the longest, at 5 seconds total. This animation is therefore the one you want to trigger your transition upon. You do so by creating an AnimationListener object, which has callbacks for the animation life cycle events: start, end, and repeat. In this case, only the onAnimationEnd() method has an interesting implementation. Here is the code to create the AnimationListener and implement the onAnimationEnd() callback:

Animation fade2 = AnimationUtils.loacMnimation(this, R.anim.fade_in2); fade2.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) {

startActivity(new Intent(QuizSplashActivity.this,

QuizMenuActivity.class)); QuizSplashActivity.this.finish();

Now if you run the Been There, Done That! application again, either on the emulator or on the handset, you see some nice animation on the splash screen. The user then transitions smoothly to the main menu screen, which is the next screen on your to-do list.

0 0

Post a comment