开发者

performSelectorOnMainThread equivalent in Java for Android

开发者 https://www.devze.com 2022-12-30 08:44 出处:网络
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 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:

  1. manual threading + Handler or runOnUiThread(..) available from Activity for posting UI changes
  2. AsyncTask
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号