I ran into a piece of Android code. I don’t quite understand the purpose of the callback because it’s empty.
In Animation.java
private AnimationCallback callback = null;
public Animation(final AnimationCallback animationCallBack) {
this();
callback = animationCallBack;
}
public void stop() {
if (callback != null) {
callback.onAnimationFinished(this);
}
active = false;
}
public interface AnimationCallback { void onAnimationFinished(final Animation animation); }
but in AnimationCallback there’s only
public interface AnimationCallback {
void onAnimationFinished(final Animation animation);
}
I guess my question is what does callback.onAnimationFinished(this) do? There doesn’t seem to have anything inside the routine.
The constructor is declared to take anything that implements the
AnimationCallbackinterface. In Java, an interface defines the behavior of an object without specifying any of its behavior.The actual object that gets passed to the constructor is some concrete class that implements the
AnimationCallbackinterface. You’d have to know the actual class of the object being used to know what it does.Per request, here’s a simple (and fairly useless) class that just logs the fact that an animation has finished: