Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Is a while loop efficient?

Currently I'm using the following construction:

while(continue)
{
    if(somethingChanged)
    {
        draw();
    }
}

Is this way of waiting efficient, or is there a better way to do this?

--

As requested, more info:

I'm drawing on a SurfaceView, with a Thread locking the Canvas and calling the onDraw(Canvas) method. When the thing I have drawn hasn't changed, I don't need to call the onDraw(Canvas) method, so I keep a boolean somethingChanged.

Also, when I touch the screen, I draw let's say a circle at the point of touch, so when I'm touching the screen, somethingChanged is true.

like image 477
nhaarman Avatar asked Jul 09 '26 16:07

nhaarman


1 Answers

You can also use a wait() and make the other threads notify() this one when something has changed (if the somethingChanged is changed by other threads).

like image 157
Guillaume Brunerie Avatar answered Jul 13 '26 20:07

Guillaume Brunerie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!