Programmatically determine whether the code is executing from the UI thread or not
<p>In my Android app, I am extracting the code to update UI elements into a separate utility package for reuse. I would like my code to be proactive and update the UI differently if the current execution context is from a UI thread versus a non-UI thread.</p>

<p>Is it possible to programmatically determine whether the current execution is happening on the UI thread or not?</p>

<p>A trivial example of what I am looking to achieve is this - my app updates a lot of <code>TextView</code>s all the time. So, I would like to have a static utility like this:</p>

<pre><code>public static void setTextOnTextView(TextView tv, CharSequence text){
    tv.setText(text);
}
</code></pre>

<p>This obviously won't work if called from a non-UI thread. In that case I would like to force the client code to pass in a <code>Handler</code> as well, and post the UI operation to the handler.</p>
