如果多次启动Android服务会怎样? [英] What happens if a Android Service is started multiple times?

查看:404
本文介绍了如果多次启动Android服务会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下代码:

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服务会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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