Fisher
Fisher

Reputation: 1794

How can i pause executing code until animation finishes

public void startGameButtonClicked(View view) { final TextView shadow = (TextView) findViewById(R.id.main_menu_start_game_button_shadow);

    final Animation animation = AnimationUtils.loadAnimation(this, R.anim.main_menu);
    shadow.startAnimation(animation);

    /** Ugly prototype pausing */
    final long startTime = System.currentTimeMillis();
    while ((System.currentTimeMillis() - startTime) < 600) {
        Log.i("test", Boolean.toString(animation.hasEnded()));
    }


    final Intent intent = new Intent();
    intent.putExtra(EXTRA_BUTTON_ID, START_GAME_BUTTON);

    setResult(RESULT_OK, intent);

    finish();
}

My animation has duration = 400, how can i pause everything except animation after calling shadow.startAnimation(animation); ? I asking becouse, as you can see - animation is set for button click action, which kills current activity, so animation isnt shown completely.

Upvotes: 1

Views: 1250

Answers (1)

ognian
ognian

Reputation: 11541

You must define "pause everything" to get an answer for it.

What I'll propose is to implement AnimationListener in your Activity, and point it to the Animation. Then in onAnimationEnd() simply call finish().

Upvotes: 1

Related Questions