0

How to start an activity after the animation has ended. I have added android:oneshot="true" in the xml but how to start a new activity after this animation has stopped.I have attached the entire code below. Please let me know how to start new activity.If I use this code without showing my animation it goes to the another acitivity.

public class MainActivity extends Activity  {

ImageView iv;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}
public void onWindowFocusChanged (boolean hasFocus) {
     super.onWindowFocusChanged(hasFocus);
        AnimationDrawable animation = (AnimationDrawable) iv.getBackground();

        if(hasFocus) {          
            animation.start();
                startActivity(new Intent(MainActivity.this,second.class));

        } else {
            animation.stop();

        }

    }
public void onStart() {
    {
        super.onStart();

        iv = (ImageView)findViewById(R.id.imageView1);
        iv.setBackgroundResource(R.animator.animation);

    }
}

}

raggedycoder
  • 495
  • 1
  • 6
  • 18

1 Answers1

1

One way for sure you can use onAnimationListener, and be really interested into implementing the onAnimationEnd method of the listener interface.

Something like this:

animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                startActivity(new Intent(MainActivity.this,second.class));
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
Marko Niciforovic
  • 3,561
  • 2
  • 21
  • 28