Bas
Bas

Reputation: 891

Android onDraw() is a suspicous method call

For an Android canvas game I use the following (minimized) method to request a redraw of the SurfaceView:

    private void refreshView() {
        c = surfaceView.getHolder().lockCanvas();
        synchronized (surfaceView.getHolder()) {
            surfaceView.onDraw(c);
        }

But since the last android sdk (22.2.1) it gives me a Lint warning on surfaceView.onDraw

Suspicious method call; should probably call "draw" rather than "onDraw"

When I use draw instead of onDraw, the screen stays black. When I use postInvalidate(), the rendering performance reduces.

Is there something I am doing wrong? Is there a better way to implement this?

Upvotes: 3

Views: 6368

Answers (4)

Bharat Kumar Emani
Bharat Kumar Emani

Reputation: 3434

Instead of onDraw(c) use draw(c) and change Method onDraw(Canvas canvas) to draw(Canvas canvas) .hope this helps

Upvotes: 2

Mr.Moustard
Mr.Moustard

Reputation: 1307

I know is not the best solution, but I used @SuppressLint("WrongCall") to avoid the error message.

Upvotes: 3

dull_boy
dull_boy

Reputation: 308

I meet the same error. After I change the onDraw function to another name, ie. Fix_onDraw, all thing is ok.

Upvotes: 0

Display Name
Display Name

Reputation: 8128

By convention, methods from Android API named like On*** should not be called directly by your code, but only by Android OS itself. I hope, someone will tell you what to use instead of it in this situation...
For the performance: if performance can become a problem, why don't you use OpenGL? (or a library that uses OpenGL)

Upvotes: 3

Related Questions