android - SurfaceView drawText flickering -


i trying make simple stopwatch using surfaceview. shows hundredths of second, tries update possible in order keep smooth animation. works absolutely fine on tablet running 4.0.3 , phone running 4.0.4, when try on 4.4.4, there appears tearing cannot explain.

this emulator running 4.4.4, problem happens on hardware device well.

the bottom image shows should happening, , part works. however, once every few seconds there flicker. when manage pause @ right time, see some of digits transposed right. ever move right (a la top image). happens fraction of second, long enough cause noticeable flicker.

note digits positioned on canvas using values calculated once (in onmeasure()) , stored in class fields. not change after initialized. tested logging pixel values of each inside ondraw().

in image above minutes values transposed, other digits. seem transposed in set; both minutes, both seconds or both centiseconds.

further: affects drawtext(). have more complex versions of stopwatch lots of paths, circles, etc. problem happens text.

i looked @ several questions , comments on , elsewhere. here's have determined:

  • i not think buffer issue. behaviour seems similar descriptions of buffer-based tearing, in case don't think problem can old data being posted screen, because digits never drawn in positions shown.

  • i read in comment might related function updates values being called more once between ondraw() method calls. have tried throttling update, problem persists.

  • i tried drawing temporary bitmap , using canvas.drawbitmap() in ondraw() function, again no avail.

basically, want know:

  • what causing issue?
  • why in higher versions of android?
  • what can it?

after reading @fadden's comments, able search bit more effectively.

it seems error in trying call ondraw() in animation thread. when changed 1 call postinvalidate(), fixed problem. in short, inside of animation loop looks this:

holder = view.getholder(); canvas = holder.lockcanvas(); if (canvas != null) {     synchronized (holder) {         if (view != null) {             view.debug_threadcalls++;             // not view.ondraw(), but:             view.postinvalidate();         }     } } 

as understand it, call ondraw() causes problems because results in app drawing both view , surface.

i guessing reason problem showed in more modern versions of android might because newer devices have higher refresh rates, , problem more visible. have noticed solution increased framerate on oldest device, presumably because not working hard drawing 2 places @ once.


update

following further advice extremely helpful comments below, have removed surfaceview altogether , drawing on custom view using separate animation thread. result unbelievably smooth animation on older devices, far better surfaceview! else trying animate surfaceview, say: unless have reason to, don't!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -