Java 多次启动前台?

Java 多次启动前台?,java,android,multithreading,for-loop,Java,Android,Multithreading,For Loop,我知道多次调用startService(intent)只会导致一个已启动的服务和实例,但我想知道startForeground(int、id、notification)以下是文档中关于多次调用启动服务的说明: 请注意,对Context.startService()的多个调用不会嵌套(尽管它们会导致对onStartCommand()的多个相应调用),因此无论服务启动多少次,都会停止一次 调用了Context.stopService()或stopSelf() 由于myonStartCommand()

我知道多次调用
startService(intent)
只会导致一个已启动的服务和实例,但我想知道
startForeground(int、id、notification)
以下是文档中关于多次调用启动服务的说明:

请注意,对Context.startService()的多个调用不会嵌套(尽管它们会导致对onStartCommand()的多个相应调用),因此无论服务启动多少次,都会停止一次 调用了Context.stopService()或stopSelf()

由于my
onStartCommand()
可能会被多次调用,因此可以多次调用my
startForeground(int、id、notification)
吗?如果我在for循环中调用它500次,还会只有一个实例吗

谢谢


鲁希尔

是的。顺便说一句,你为什么不试试呢?@Gavriel我怎么知道有多少个实例出现了?你计算它们:)在你的类或应用程序中创建一个静态整数。如果你没有得到正确的答案,确保你的应用程序不会在中间被杀死。