UIThread is the main thread of execution for your application. This is where most of your application code runs. All of your application components (Activities, Services, ContentProviders, BroadcastReceivers) are created in this thread, and any system calls of these components are made in this thread.
For example, let's say your application is a single Activity class. Then, in this UIThread, all lifecycle methods and most of your event processing code are run. These are methods like onCreate , onPause , onDestroy , onClick , etc. In addition, all updates for the user interface occur here. Everything that causes the user interface to update or change must happen in the user interface thread.
Learn more about your Processes and Themes application here.
When you explicitly create a new thread to run in the background, this code does not run in UIThread. So what happens if this background thread needs to do something that changes the user interface? For this, runOnUiThread is runOnUiThread . You should actually use a handler (see the link below for more information about this). It provides these background threads with the ability to execute code that can change the user interface. They do this by putting the UI change code in the Runnable object and passing it to the runOnUiThread method.
For more information on workstation flows and user interface updates, click here.
I personally use only the runOnUiThread method in my Instrumentation tests. Since test code is not executed in UIThread, you need to use this method to run code that modifies the user interface. Therefore, I use it to enter clicks and key events in my application. Then I can check the status of the application to make sure everything happened correctly.
For more information on testing and running code in UIThread, click here.
plainjimbo Sep 06 '10 at 18:13 2010-09-06 18:13
source share