可以startServce()可以从任何线程调用? [英] Can startServce() be invoked from any thread?
问题描述
大多数Android框架组件不是线程安全的,至少这是我平时工作用的假设。
但是,它是安全调用 startService()
从后台线程?
我遇到了来自戴安娜Hackborn后谁说,这是安全地调用 sendBroadcast()
从任何线程,所以我想认为这也适用于 startService()
( HTTP: //groups.google.com/group/android-developers/msg/38a09b52de93f70a )。
任何人都可以使用框架的经验对此有何评论?
谢谢!
我不知道的理论,但我相信答案是肯定的,而且很容易去尝试。只是要确保一如既往,如果你要更新的UI任何东西,把一个处理器在主线程 - 然后在服务,发送处理程序被提上了UI包含数据的消息。 P>
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屋!