tags:

views:

62

answers:

2

Hi! I have the following problem: My app has a thread that updates the game state. The app needs to make a change to the state of the View object, triggered by this thread. The documentation for View states that it should only be modified from the UI thread, and that a Handler should be used to place and handle events.

Yet, there is a function post() in View where I can post a Runnable object that will execute in the UI thread without involvement of Handler. Can I not call this function from threads other than the UI thread??

I'm confused!

+1  A: 

Yes you can use View.post(). Internally it uses a handler to post the Runnable.

BrennaSoft
+1  A: 

If you want to run some arbitrary code on the UI thread from a background thread, you can use Activity's runOnUiThread():

   runOnUiThread(new Runnable() {
        @Override
        public void run() {

        }
    });
Brandon