[英]performSelectorOnMainThread equivalent in Java for Android
I have an iPhone application and I am porting it over to Android. 我有一个iPhone应用程序,正在将其移植到Android。
I have a service/controller that spawns new threads to perform some network tasks. 我有一个服务/控制器,它会产生新的线程来执行某些网络任务。
I use performSelectorOnMainThread
in my iPhone app. 我在iPhone应用程序中使用
performSelectorOnMainThread
。 How can I have my Java app do the same or similar thing? 如何让我的Java应用执行相同或相似的操作?
Assuming performSelectorOnMainThread
does what I think it does, look at runOnUiThread()
in Activity
, or post()
on Handler
or any of your Views
(ie, your GUI widgets). 假设
performSelectorOnMainThread
做了我想做的事情,请查看Activity
中的runOnUiThread()
或Handler
或任何Views
(即您的GUI窗口小部件)上的post()
)。
Though I generally agree with alex's answer -- use AsyncTask
where possible, rather than forking your own threads. 尽管我通常同意alex的回答-尽可能使用
AsyncTask
,而不要分叉自己的线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.