hosein kordloo
hosein kordloo

Reputation: 21

Start an Activity after an animation has completed

I have the following animation set in onClick. I am trying to start my activity after the animation is done, but it isn't working.

CODE

final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
iv1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
        iv1.startAnimation(anim);

        Intent i = new Intent();
        i.setClass(MainActivity.this, P2.class);
        startActivity(i);
    }
});

QUESTION

How do I wait for the animation to complete before starting my activity?

Upvotes: 0

Views: 1242

Answers (2)

user4300069
user4300069

Reputation:

Use animation listener

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

    }

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

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
};
anim.setAnimationListener(listener);
iv1.startAnimation(anim);

Upvotes: 2

Related Questions