[android-developers] how to check if the current thread is in the ui thread?

2010-07-13 Thread guich
Hi,

I have a situation where i want to show a dialog. However, the code
that calls the method to show the dialog can be running either in the
ui thread or not.

How can i find if the current thread is running in the ui thread or
not?

thanks

   guich

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] how to check if the current thread is in the ui thread?

2010-07-13 Thread Mark Murphy
On Tue, Jul 13, 2010 at 1:38 PM, guich guiha...@gmail.com wrote:
 I have a situation where i want to show a dialog. However, the code
 that calls the method to show the dialog can be running either in the
 ui thread or not.

 How can i find if the current thread is running in the ui thread or
 not?

Actually, for that case, you may as well just wrap it in a Runnable
and call runOnUiThread():

runOnUiThread(new Runnable() {
public void run() {
// launch your dialog here
}
});

This will ensure that the code runs on the UI thread, regardless of
whether you are on the UI thread or not.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 2.2 Programming Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en