android - 意向服务问题

标签 android android-intent intentservice

假设我要通过 startService(intentservice) 多次调用一个 Intent 服务,它会同时运行该服务的多个实例还是要排队?

最佳答案

如果你多次调用startService,而且服务已经在运行,它的onStart方法每次都会被调用,onCreate只会调用如果它不存在,则一次。 该服务将提供单个实例。

看这个documentation ,这里在下面的部分中明确提到了

"请注意,对 Context.startService() 的多次调用不会嵌套(尽管它们确实会导致对 onStartCommand() 的多次相应调用),因此无论启动多少次,一旦 Context.stopService 服务就会停止() 或 stopSelf() 被调用;“

关于android - 意向服务问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8820229/

相关文章:

android - 如何在 RecyclerView 中显示 Firestore 时间戳(日期和时间)

android - 广播 protected Intent 时出现 SecurityException

android - 将 "/app"而不是 "/appinst"与 android :pathPattern (working on an intent-filter) 匹配

android - Activity 泄露了最初在此处注册的 IntentReceiver com.mopub.mobileads.MoPubView。您是否错过了对 unregisterReceiver() 的调用?

android - 多次启动IntentService android

android - 如何在android中实现后台队列?

Android Studio 找不到物理设备或 AVD

java - 释放 JNI 数组

android - 即使我使用不同的数据创建一些 Intent ,我也会从通知中获得相同的额外数据

android - 检查网络连接android