我创建了一个使用对象downloadData1
的服务DownloadService1
。
现在,我想使用对象 downloadData1
和 downloadData2
来同时
执行 2 个下载操作,但我不想创建 extact
DownloadService1
的副本,例如将与 downloadData2
一起使用的 DownloadService2
。
有没有办法创建多个服务实例来实现我想要的?
最佳答案
How to create multiple instances of a service in Android?
据我所知不可能创建一个服务的多个实例
仅运行一个服务实例
如果多次调用 startService()
不会导致启动多个服务。
当你调用startService()
时,只有两种可能性
If Service in not started previously then it will start as per service life cycle
If Service is previously started then only
onStartCammand()
will get called with desired intent which you have passed to it .
有关更多信息,请阅读文档 service
关于android - 如何在Android中创建一个服务的多个实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077531/