5

Is it possible to get these values programmatically:

  • frames per second
  • how often the method onDraw() is called if the whole View is invalidated immediately.
A.G.
  • 2,037
  • 4
  • 29
  • 40

1 Answers1

4

1) Here is how I'm counting fps:

public class MyView extends View {
    private int    mFPS = 0;         // the value to show
    private int    mFPSCounter = 0;  // the value to count
    private long   mFPSTime = 0;     // last update time

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (SystemClock.uptimeMillis() - mFPSTime > 1000) {
            mFPSTime = SystemClock.uptimeMillis();
            mFPS = mFPSCounter;
            mFPSCounter = 0;
        } else {
            mFPSCounter++;
        }

        String s = "FPS: " + mFPS;
        canvas.drawText(s, x, y, paint);

        invalidate();
    }
}

or just write your own object that would calculate this for you :)...

2) Try using

Log.d(tag, "onDraw() is called");

in your onDraw() method.

GV_FiQst
  • 1,487
  • 14
  • 30