可以startServce()可以从任何线程调用? [英] Can startServce() be invoked from any thread?

查看:91
本文介绍了可以startServce()可以从任何线程调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数Android框架组件不是线程安全的,至少这是我平时工作用的假设。

但是,它是安全调用 startService()从后台线程?

我遇到了来自戴安娜Hackborn后谁说,这是安全地调用 sendBroadcast()从任何线程,所以我想认为这也适用于 startService() HTTP: //groups.google.com/group/android-developers/msg/38a09b52de93f70a )。

任何人都可以使用框架的经验对此有何评论?

谢谢!

解决方案

我不知道的理论,但我相信答案是肯定的,而且很容易去尝试。只是要确保一如既往,如果你要更新的UI任何东西,把一个处理器在主线程 - 然后在服务,发送处理程序被提上了UI包含数据的消息

Most Android framework components are not thread safe—at least this is the assumption that I usually work with.

However, is it safe to invoke startService() from a background thread?

I came across a post from Dianne Hackborn who says that it is safe to call sendBroadcast() from any thread, so I want to assume that this is also true for startService() (http://groups.google.com/group/android-developers/msg/38a09b52de93f70a).

Can anyone with framework experience comment?

Thanks!

解决方案

I don't know the theory but I believe the answer is yes, and it is easy to try. Just be sure that as always, if you are going to update anything on the UI, to put a Handler in your main thread - and then in the Service, send that Handler a Message containing the data to be put on the UI.

这篇关于可以startServce()可以从任何线程调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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