title: How to make a custom Animation play once
body: <p>here is my animation class that i'm using to draw Objects in a SurfaceView :  </p>
  
  <pre><code>import android.graphics.Bitmap;
  
  public class Animation {
  private Bitmap[] frames;
  private int currentFrame;
  private long startTime;
  private long delay;
  private boolean playedOnce;
  
  public void setFrames(Bitmap[] frames)
  {
      this.frames = frames;
      currentFrame = 0;
      startTime = System.nanoTime();
  }
  public void setDelay(long d){delay = d;}
  public void setFrame(int i){currentFrame= i;}
  
  public void update()
  {
      long elapsed = (System.nanoTime()-startTime)/1000000;
  
      if(elapsed&gt;delay)
      {
          currentFrame++;
          startTime = System.nanoTime();
      }
      if(currentFrame == frames.length){
          currentFrame = 0;
          playedOnce = true;
      }
  }
  public Bitmap getImage(){
      return frames[currentFrame];
  }
  public int getFrame(){return currentFrame;}
  public boolean playedOnce(){
      return playedOnce;
  }
  </code></pre>
  
  <p>}<br>
  but!, <code>playedOnce</code> method isn't working!<br>
  the animation keeps looping..<br>
  am i missing something? how to fix this?  </p>