来自不同线程调用的onCreate同时 [英] calling onCreate from different threads at the same time
问题描述
我已阅读Android文档在一张code是onCreate方法内同步的同步适配器。
AFAIK的Android只能创建一个服务的一个实例的话,可以使用Android在同一时间从不同的线程调用的onCreate?或者是它可以调用的onCreate前一个服务方法已经完成(使用AIDL)?
I have read Android documentation in which a piece of code is synchronized inside the onCreate method, Sync Adapter. AFAIK Android only creates one instance of a Service so, can Android call onCreate from different threads at the same time? or is it possible to call a Service method before onCreate has finished (using AIDL)?
推荐答案
您链接到文件(关于一个线程安全的方式创建 SyncAdapter
)是没有意义的。 的onCreate()
A 服务
只会被调用在主线程,所以不存在这种可能性,这ISN ŧ线程安全的。
The documentation you linked to (regarding creating SyncAdapter
in a thread-safe manner) makes no sense. onCreate()
of a Service
is only ever called on the main thread, so there is no possibility that this isn't thread-safe.
此外,你不能打电话之前使用AIDL任何方法的onCreate()
完成,因为你首先需要绑定到服务
,你不能绑定到服务
直到的onCreate()
完成。
Also, you cannot call any methods using AIDL before the onCreate()
completes, because you would first need to bind to the Service
, and you can't bind to the Service
until onCreate()
completes.
这篇关于来自不同线程调用的onCreate同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!