0

I have an animation that is to be displayed on click of an image view and finish the animation before going to another activity.I have been trying to do this.

Here is my code :

public void myAnimation() 
    AnimationDrawable animation;
    animation = new AnimationDrawable();
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_monotone),
            1000);
    animation.addFrame(getResources()
            .getDrawable(R.drawable.large_ring_eal), 1000);
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_blue), 1000);
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_monotone),
            1000);

    animation.setOneShot(true);
    img_big_2_back.setOnClickListener(new OnClickListener){
    img_big_2_back.setBackgroundDrawable(animation);

        try {
            animation.start();
            Thread.sleep(3000);

        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Intent i1 = new Intent(MAinACtivity.this,SecondActivity.class);
        startActivity(i1);
    });
}

Can any one let me know where i am going wrong

avalancha
  • 1,457
  • 1
  • 22
  • 41
user2717079
  • 299
  • 1
  • 3
  • 13

2 Answers2

3

Man, if your activity is getting called even before animation is finished, then try setting Animation Listener, you can start activity from there once animation finish callback is received.

http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html

Techfist
  • 4,314
  • 6
  • 22
  • 32
1

First of all, why there is a Thread Sleep in your code? That's not the way to wait for animation to get over. Try the answers of this thread. You can use the method described in this answer

Community
  • 1
  • 1
Rajeev
  • 1,374
  • 1
  • 11
  • 18