问题描述
如果我有以下代码:
Intent intent = new Intent(this,DownloadService.class);
for(int i=0;i<filesArray.length;i++){
startService(intent);
}
在此代码中,DownloadService
扩展了IntentService
.
所以现在,当我调用startService(intent)
时,这意味着每次调用startService(intent)
时我都在启动新服务,或者这意味着DownloadService
运行一次,然后每次我调用它只会传递具有不同startId的不同意图.
So now when I'm calling startService(intent)
does that mean that I'm starting a new service every time startService(intent)
is called or does that mean that DownloadService
is run once and then each time I call startService(intent)
it will just pass a different intent with a different startId.
这有意义吗?是哪种情况?
Does this make sense, and which one of these is the case ?
推荐答案
该服务仅在一个实例中运行.但是,每次启动服务时,都会调用onStartCommand()
方法.
The Service will only run in one instance. However, everytime you start the service, the onStartCommand()
method is called.
这篇关于如果多次启动Android服务会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!