I have an iPhone application and I am porting it over to Android.
I have a service/controller that spawns new threa开发者_如何学Pythonds 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?
Options:
- manual threading + Handler or
runOnUiThread(..)
available from Activity for posting UI changes - AsyncTask
- Service for lengthy background operations
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.
精彩评论