Note that there are some explanatory texts on larger screens.

plurals
  1. PORedraw Drawable by timer using invalidateSelf() not working
    text
    copied!<p>I have my class implements Drawable. I need to redraw it periodicaly to get some "blink" effect. I am using timer.schedule to schedule invalidateSelf() but nothing happend.</p> <pre><code>private class DrawableImpl extends Drawable { private boolean blinkFlag = false; private Timer timer = new Timer(false); private int maxFlashCount = 21; private int intervalBetweenFlashesInMs = 100; private int currentFlashNumber = 0; @Override public void draw(Canvas canvas) { Log.i(TAG, "draw"); /*draw stable part*/ if (blinkFlag ) { Log.i(TAG, "blink"); /*draw bliking part*/ } blinkFlag = !blinkFlag; final DrawableImpl drawableImpl = this; if (currentFlashNumber &lt; maxFlashCount) { Log.i(TAG, "schedule"); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { Log.i(TAG, "run from back"); drawableImpl.invalidateSelf(); } }); } }, intervalBetweenFlashesInMs); currentFlashNumber++; } } } </code></pre> <p>In Log something like this<br> 02-08 23:07:44.791: INFO/(258): draw<br> 02-08 23:07:44.791: INFO/(258): blink<br> 02-08 23:07:44.791: INFO/(258): schedule<br> 02-08 23:07:45.011: INFO/(258): run from back<br> 02-08 23:07:45.021: INFO/(258): draw<br> 02-08 23:07:45.021: INFO/(258): schedule<br> 02-08 23:07:45.171: INFO/(258): run from back<br> 02-08 23:07:45.171: INFO/(258): draw<br> 02-08 23:07:45.171: INFO/(258): blink<br> 02-08 23:07:45.171: INFO/(258): schedule<br> 02-08 23:07:45.331: INFO/(258): run from back</p> <p>Why it didn`t work? Should I use another methods for that?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload