Search code examples
androidtextviewscreensettext

Screen refresh time of an android device


Is there a way to measure the screen refresh time of an android device?

I want to know the time spent drawing a text on the screen after calling the setText method.


Solution

  • You can override the onDraw method of a TextView to find out when it's actually redrawn.

    public class MyTextView extends android.widget.TextView {
        private long mUpdateTime;
        public MyTextView(Context context) {
            super(context);
        }
        public void mySetText(CharSequence text) {
            mUpdateTime = System.currentTimeMillis();
            super.setText(text);
        }
        @Override
        public void onDraw(Canvas c) {
            super.onDraw(c);
            long refreshTime = System.currentTimeMillis() - mUpdateTime;
            //Do something with refreshTime
        }
    }