Alex Goncalves
Alex Goncalves

Reputation: 69

How to start a new activity after the end an animation?

Am quite new to Android, I could not found a thread on how to start new activity on anim end.

Here is my code:

public class Intro extends Activity {

    AnimationDrawable anim = new AnimationDrawable();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);
        ImageView iv =(ImageView) findViewById(R.id.imageView1);          
        iv.setBackgroundResource(R.anim.animation);    
        anim = (AnimationDrawable) iv.getBackground(); 

        iv.post(new Runnable(){    
            public void run(){    
                anim.start();        
        }

        });

    }

}

Upvotes: 2

Views: 282

Answers (1)

Tobias Ritzau
Tobias Ritzau

Reputation: 3327

As far as I know there is no callback mechanism to determine when an AnimationDrawable has finished an iteration. What you can do is to query the number of frames and the delay of each frame. Sum that up and make a delayed post with that duration. In that callback you can start your second activity.

And note that it is a bit dangerous to start the animation the way you do it. The docs say:

It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.

Upvotes: 2

Related Questions