Ryan
Ryan

Reputation: 46

The animation doesn't work properly when the activity resume

All

I am developing an android app, the first activity is the MenuActivity, there is a button in the MenuActivity, I would like to make the button slide into the screen with animation when the menuActivity startup, so I write the following code in the onResume method of the MenuActivity.

@Override
protected void onResume(){
	super.onResume();
	Animation animation = AnimationUtils.loadAnimation(MenuActivity.this,
			android.R.anim.slide_in_left);
	animation.setInterpolator(new OvershootInterpolator());
	button.startAnimation(animation);
}

When I run the app, the MenuActivity show up for the first time, the button can slide in the screen with the animation properly, and then I click on the button, it will start another activity called ContentActivity, and then I click the back button to close the ContentActivity, the MenuActivity show up again, but for the second time the button doesn't slide in the screen with animation any more, the button just show up in the screen immediately with not translation animation.

Can anyone help me out from this issue??

Upvotes: 0

Views: 516

Answers (1)

Biu
Biu

Reputation: 1076

Override the onWindowFocusChanged() method and move your animation code there instead.

public void onWindowFocusChanged(boolean hasFocus)
{
     if(hasFocus)
     {
          //your code here
     }
}

Upvotes: 1

Related Questions