Reputation: 167
If I am not mistaken, you can find out if the current thread is the UI thread by doing:
if (Looper.myLooper() == Looper.getMainLooper())
/* we are in the UI thread */
How can I post a task to the UI thread/queue?
if (Looper.myLooper() == Looper.getMainLooper())
X.execute(new Runnable() { ... });
Here, X is the queue/handler of the UI Thread. What is X, and can get I get it statically?
I would like to send this task without being forced to have a reference to my activity or anything else. Is this possible?
Thanks!
Upvotes: 0
Views: 2343
Reputation: 982
I would probably recommend looking at context.runOnUiThread(Runnable r); No need to check the looper - the runOnUiThread(...) function will do that for you.
Upvotes: 1