0

Hi i'm running an animation and after 2 seconds i want to stop it and close the whole application.

This is my animation:

public void onImageButtonOkClick(View view) {
            setContentView(R.layout.success);

            final ImageView mAnimLogo = (ImageView) findViewById(R.id.loading_image);
            final AnimationDrawable mAnimation = (AnimationDrawable) mAnimLogo.getDrawable();

                mAnimLogo.post(new Runnable() {
                    @Override
                    public void run() {
                        mAnimLogo.setVisibility(View.VISIBLE);
                        mAnimation.start();
                    }
                });
}

and i tried to use finish() after a timer was called - the application closed, but without any animations.

Any Suggestions?

Edit:

public void delay() {
    Timer timer = new Timer();
    try {
        synchronized(timer){
            timer.wait(2000);
            getParent().finish();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Schrims
  • 3
  • 2

1 Answers1

0

i solved this problem by using a recursive function to check the animation

private void checkAnimation(AnimationDrawable animationDrawable){
    final AnimationDrawable animation = animationDrawable;
    int timeBetweenChecks = 300;
    Handler h = new Handler();
    h.postDelayed(new Runnable(){
        public void run(){
            if (animation.getCurrent() != animation.getFrame(animation.getNumberOfFrames() - 1)){
                checkAnimation(animation);
            } else{
                finish();
            }
        }
    }, timeBetweenChecks);
};
Schrims
  • 3
  • 2