4

I'm developing an Android 2.2 application.

I have an event listener on an activity, and I want to set visible a TextView when I receive an event. But there is an error:

I only can set it visible from UI thread.

In C# and Windows Mobile there is a BeginInvoke. Is there something similar in Android?

Thanks.

VansFannel
  • 45,055
  • 107
  • 359
  • 626

1 Answers1

0

You can use Activity#runOnUiThread or an AsyncTask as the two easiest ways to duplicate the BeginInvoke functionality; with runOnUiThread being the one most similar.

For more complicated or performance orientated needs (i.e., you do not want to keep creating a large number of Runnable objects) you can use a Handler. However, I do not recommend it as your first choice.

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • An article about AsyncTask and another ways to solve the problem: http://developer.android.com/resources/articles/painless-threading.html – VansFannel Jan 07 '11 at 19:28