android - 如何在Android中创建一个服务的多个实例?

标签 android service

我创建了一个使用对象downloadData1的服务DownloadService1。 现在,我想使用对象 downloadData1downloadData2同时执行 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/

相关文章:

c# - 使用 Team Foundation Server DLL 作为类库中的引用

linux - 如果 upstart 脚本中不存在,如何创建文件夹

android - MediaPlayer 应该在单独的线程中运行吗?

android - 如何在 Android Studio 中使用 Doxygen 插件?

java - Eclipse 将不会在 Linux 中生成 R.Java

android - onNewIntent() 上的 NFC 标签为空

android - 如何跟踪第二根手指的运动

java - 如何保持 Android 应用程序始终运行(Service 和 BroadcastReceiver)?

在 ListFragment 中填充自定义 View 时出现 Android U_MISSING_RESOURCE_ERROR

service - Angular 服务应该有状态吗?