views:

34

answers:

2

I have an iPhone application and I am porting it over to Android.

I have a service/controller that spawns new threads to perform some network tasks.

I use performSelectorOnMainThread in my iPhone app. How can I have my Java app do the same or similar thing?

+2  A: 

Options:

  1. manual threading + Handler or runOnUiThread(..) available from Activity for posting UI changes
  2. AsyncTask
  3. Service for lengthy background operations
alex
That's the answer if Mr. White wishes to replace his current threads plus handle updating the UI on the main application thread. And that's probably a good idea, as "threads" plural gets a wee bit scary.
CommonsWare
@CommonsWare Agreed and edited. :)
alex
I used AsyncTask. thanks!
Daniel A. White
+1  A: 

Assuming performSelectorOnMainThread does what I think it does, look at runOnUiThread() in Activity, or post() on Handler or any of your Views (i.e., your GUI widgets).

Though I generally agree with alex's answer -- use AsyncTask where possible, rather than forking your own threads.

CommonsWare