Reputation: 5413
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.
Upvotes: 0
Views: 143
Reputation: 234797
The constructor is declared to take anything that implements the AnimationCallback
interface. 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 AnimationCallback
interface. 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:
public AnimationFinishedLogger implements AnimationCallback {
public void onAnimationFinished(final Animation animation) {
Log.i("AnimationLogger", "Animation finished");
}
}
Upvotes: 3