How to implement a paint-update loop?
<p>I want to create a paint and update loop in android for game animation on a canvas but I am having trouble as I can't seem to get the threading to work appropriately. It seems to crash almost immediately. Here is what I have tried:</p>

<pre><code>    // Create the thread supplying it with the runnable object
    Thread thread = new Thread(runnable);

    // Start the thread in oncreate()
    thread.start();


    class runner implements Runnable {
    // This method is called when the thread runs
    long wait = 1000;

    public void run() {

    update();
    }

    public void update()
    {
        try{
          Thread.currentThread();
            //do what you want to do before sleeping
          Thread.sleep(wait);//sleep for 1000 ms
          //do what you want to do after sleeping
        }
        catch(InterruptedException ie){
        //If this thread was interrupted by another thread 
        }

        run();
    }
}
</code></pre>

<p>Also when I drop the wait down lower it crashes faster.</p>

<p>Is there a more appropriate way to approach this?</p>

<p>Changed to this:</p>

<pre><code>class runner implements Runnable {
// This method is called when the thread runs
long wait = 10;
boolean blocked = false;

public void run() {

    if(!blocked){
        blocked = true;
        paint();
    }
}


public void paint()
{

    update();
}


public void update()
{
    try{
      Thread.currentThread();
        //do what you want to do before sleeping
      Thread.sleep(wait);//sleep for 1000 ms
      //do what you want to do after sleeping
    }
    catch(InterruptedException ie){
    //If this thread was interrupted by another thread 
    }

    paint();
}
</code></pre>

<p>}</p>

<p>This results in the same error... :/</p>
