How does HandlerThread process messages?
I'm implementing my own [SurfaceView][1] which contains a Thread object whose purpose is to draw various graphical objects to the Canvas. In the constructor of my SurfaceView I set up the objects to be drawn and the Thread object (currently) only positions them to the Canvas as appropriate.

I have need now to change one of the objects created in the constructor of my SurfaceView (the object is a Bitmap) after the user has performed a particular action (i.e. the Thread object is running). This means communication between the app's GUI thread and the thread executing my Thread object. I discovered [this][2] page which details the use of the [HandlerThread][3] class, perfect for what I need to achieve. However I need to be sure of how this class works to ensure there is no memory consistency errors.

The following is psuedo code of my own class with a lot stripped out for clarity:

    public MyThread extends Thread {
    boolean _run = true;
    public void run(){
    
    // Create HandlerThread object
    // Create Looper object
    // Create Handler object
    while (_run){
    // DRAW the Bitmap in this loop
    }
    }
    
    public boolean handleMessage(Message message){
    /*
    ALTER the Bitmap here as required
    */
    }
    }

 
    public MyThread extends Thread {
    boolean _run = true;
    public void run(){
    
    // Create HandlerThread object
    // Create Looper object
    // Create Handler object
    while (_run){
    // DRAW the Bitmap in this loop
    }
    }
    
    public boolean handleMessage(Message message){
    /*
    ALTER the Bitmap here as required
    */
    }
    }

As I understand it the handleMessage() method is executed by the same thread executing the run() method. However because handleMessage() ALTERS the the Bitmap whereas run() DRAWS the bitmap. Can I be sure that handleMessage() will complete in its entirety before the thread returns to the run() method?
  [1]: http://developer.android.com/reference/android/view/SurfaceView.html
  [2]: http://developer.android.com/reference/android/os/HandlerThread.html
  [3]: http://developer.android.com/reference/android/os/HandlerThread.html
How does HandlerThread process messages?
===

I'm implementing my own [SurfaceView][1] which contains a Thread object whose purpose is to draw various graphical objects to the Canvas. In the constructor of my SurfaceView I set up the objects to be drawn and the Thread object (currently) only positions them to the Canvas as appropriate.

I have need now to change one of the objects created in the constructor of my SurfaceView (the object is a Bitmap) after the user has performed a particular action (i.e. the Thread object is running). This means communication between the app's GUI thread and the thread executing my Thread object. I discovered [this][2] page which details the use of the [HandlerThread][3] class, perfect for what I need to achieve. However I need to be sure of how this class works to ensure there is no memory consistency errors.

The following is psuedo code of my own class with a lot stripped out for clarity:

    public MyThread extends Thread {
    boolean _run = true;
    public void run(){
    
    // Create HandlerThread object
    // Create Looper object
    // Create Handler object
    while (_run){
    // DRAW the Bitmap in this loop
    }
    }
    
    public boolean handleMessage(Message message){
    /*
    ALTER the Bitmap here as required
    */
    }
    }

 
    public MyThread extends Thread {
    boolean _run = true;
    public void run(){
    
    // Create HandlerThread object
    // Create Looper object
    // Create Handler object
    while (_run){
    // DRAW the Bitmap in this loop
    }
    }
    
    public boolean handleMessage(Message message){
    /*
    ALTER the Bitmap here as required
    */
    }
    }

As I understand it the handleMessage() method is executed by the same thread executing the run() method. However because handleMessage() ALTERS the the Bitmap whereas run() DRAWS the bitmap. Can I be sure that handleMessage() will complete in its entirety before the thread returns to the run() method?
  [1]: http://developer.android.com/reference/android/view/SurfaceView.html
  [2]: http://developer.android.com/reference/android/os/HandlerThread.html
  [3]: http://developer.android.com/reference/android/os/HandlerThread.html