运行 同一 android 服务的多个实例
Running multiple instances of the same android service
如果我使用 startService()
后跟 bindService()
创建一个 android 服务,我从不调用 stopService()
。
现在,每次我的应用程序调用 startService()
和 bindService()
时,它会创建服务的新实例还是重用现有实例?
如果创建了一个新实例...旧实例仍然是运行还是已终止?
它不会创建另一个服务,而是将您的启动 Intent 重新传递到 onNewIntent() 方法中
will it create a new instance
没有。如果您正在调用 startService()
,即使服务已经 运行ning,它将调用 onStartCommand()
并更新 Intent
Ps,
服务将 运行 仅在一个进程中。所以毫无疑问再创建一个实例
如果我使用 startService()
后跟 bindService()
创建一个 android 服务,我从不调用 stopService()
。
现在,每次我的应用程序调用 startService()
和 bindService()
时,它会创建服务的新实例还是重用现有实例?
如果创建了一个新实例...旧实例仍然是运行还是已终止?
它不会创建另一个服务,而是将您的启动 Intent 重新传递到 onNewIntent() 方法中
will it create a new instance
没有。如果您正在调用 startService()
,即使服务已经 运行ning,它将调用 onStartCommand()
并更新 Intent
Ps, 服务将 运行 仅在一个进程中。所以毫无疑问再创建一个实例