启动服务多次? [英] Starting a service multiple times?

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

问题描述

如果我有以下的code:

If I have the following code:

Intent intent = new Intent(this,DownloadService.class);     
for(int i=0;i<filesArray.length;i++){        
     startService(intent);          
}

在此code下载服务延伸IntentService。所以,当我打电话startService(意向),现在这是否意味着我开始了新的服务,每次startService(意向)被调用或者这是否意味着下载服务一旦运行,然后我每次调用startService(意向)时它会只是通过不同的意图有不同的startId。这是否有意义,以及这些哪一个是这样吗?

In this code DownloadService extends IntentService. So now when I'm calling startService(intent) does that mean that i'm starting a new service everytime startService(intent) is called or does that mean that DownloadService is ran 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.

这是记载<一个href="http://developer.android.com/guide/topics/fundamentals/services.html#StartingAService">here

这篇关于启动服务多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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