启动Android的服务已经运行? [英] Starting Android service already running?
问题描述
当然,这是一个简单的问题。如果我开始一个服务,会发生什么
,使用下列code:
startService(新意图(这一点,myService.class));
然后我无意中想起上面的code,而服务
是没有运行?
我怕第二次调用 startservice
可以创建一个新的服务
,以便有两种不同的进程同时执行。
我怕第二呼叫startservice可以以有两个不同的过程,在同一时间执行创建一个新的服务。
没有,多计数:
-
没有,也不会创建新的服务。如果该服务已在运行,它会调用
onStartCommand()
再次,为客户提供新的意图
,但不创建第二个副本。 -
没有,也不会有两个不同的过程,在同一时间执行,因为一个服务运行在同一个进程中您的应用程序的其他部分,在默认情况下。
Sure this is a trivial question. What happens if I start a Service
, using the following code:
startService(new Intent(this,myService.class));
and then I accidentally recall the above code, while the Service
is yet running?
I'm afraid that the second call to startservice
can create a new Service
in order to have two different process executing at same time.
I'm afraid that that the second call to startservice can create a new service in order to have two different process executing at same time.
No, on multiple counts:
No, it will not create a new service. If the service is already running, it will be called with
onStartCommand()
again, to deliver the newIntent
, but a second copy is not created.No, it will not "have two different process executing at same time", because a service runs in the same process as the rest of your app, by default.
这篇关于启动Android的服务已经运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!