从服务的使用:runOnUiThread或AsyncTask的或处理程序或Post [英] from a service use: runOnUiThread or AsyncTask or Handler or Post

查看:818
本文介绍了从服务的使用:runOnUiThread或AsyncTask的或处理程序或Post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个VoIP应用。它是基于管理该VOIP逻辑一个服务和一个用户界面进行呼叫,应答等搜索
什么是更新从服务用户界面的最佳方式:结果

I'm writing a voip application. It is based on a service that manages the voip logic and a UI to make calls, answer, etc.
What is the best way to update the UI from the service:


  • runOnUiThread或

  • 的AsyncTask或

  • 处理器或

  • 发表

当使用一种方法比其他?搜索结果
我知道runOnUiThread是有问题的,因为它可能导致事件被跑出来的顺序(如果线程已经是UI线程)。

When to use one method over the other?

I know that runOnUiThread is problematic since it might cause events to be ran out of order (in case the thread is already the UI thread).

感谢。

推荐答案

据我记得,你不能直接从服务更新屏幕。你必须使用广播接收器可以捕捉到你的服务广播。我猜的AsyncTask本身使用runOnUiThread,但它提供了很好的方法来执行在后台线程的一种方法,并把结果在UI线程。

As far as I remember, you can't update the screen directly from service. You have to use broadcast receiver to catch your broadcast from service. I guess AsyncTask itself uses runOnUiThread, but it provides nice way to execute one method in background thread and put results in the UI thread.

这篇关于从服务的使用:runOnUiThread或AsyncTask的或处理程序或Post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆