动画后如何关闭应用程序?

时间:2014-09-04 09:33:20

标签: android animation android-studio wait activity-finish

嗨我正在运行一个动画,2秒后我想停止并关闭整个应用程序。

这是我的动画:

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();
                    }
                });
}

我尝试在调用计时器后使用finish() - 应用程序关闭,但没有任何动画。

任何建议?

修改

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

1 个答案:

答案 0 :(得分:0)

我通过使用递归函数检查动画来解决这个问题

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);
};