I have set animation for an image button. What I expect it to do, is fade out, and then start the next activity.
This is not what is happening.
It is starting the next activity, and then when ‘back’ is pressed, the animation is still ‘running’, and finishes the fade out. I tried various combinations of: setting the animation for a longer duration in the XML, putting the animation in a thread, and using a thread to sleep, and putting the animation in the sleep thread… I have not found with winning combination! Still not getting the animation to complete before the next activity is started.
Any help is appreciated!
XML for fade out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="1000"
/>
</set>
Code in android: (for the onClick of the imageButton)
public void onClick(View v) {
Intent intent = new Intent(Current.this, Next.class);
v.startAnimation(animationFadeOut);
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivity(intent);
}
You can also try using AnimationListener as shown below: