我在Android文档中找到了以下代码段。
A service runs in the main thread of its hosting process...
和
Note that calls to startService() are not nesting: no matter how many times you call startService(), a single call to stopService(Intent) will stop it.
我认为这意味着对startService()的多次调用不会导致服务的多个实例。
考虑以下情况:
我有一个名为MyApp
的应用,其中包含两项服务:MyService
和MyRemoteService
。在这里,MyService是本地服务,而顾名思义,MyRemoteService 在单独的流程中运行。
如果我打电话给startService()
从MyService
Activity
开始MyApp
,然后又从MyRemoteService
开始,会怎样?
MyService会运行哪个进程?在两个不同的进程中是否会运行两个不同的MyService实例:一个在托管我的主Activity的进程中,另一个实例在托管MyRemoteService的进程中运行?在这种情况下,上述两个片段会如何支撑?任何帮助都感激不尽。感谢。