Starting Android service already running?

2019-03-17 05:14发布

Sure this is a trivial question. What happens if I start a Service, using the following code:

 startService(new Intent(this,myService.class));

and then I accidentally recall the above code, while the Service is yet running?

I'm afraid that the second call to startservice can create a new Service in order to have two different process executing at same time.

1条回答
走好不送
2楼-- · 2019-03-17 05:52

I'm afraid that that the second call to startservice can create a new service in order to have two different process executing at same time.

No, on multiple counts:

  • No, it will not create a new service. If the service is already running, it will be called with onStartCommand() again, to deliver the new Intent, but a second copy is not created.

  • No, it will not "have two different process executing at same time", because a service runs in the same process as the rest of your app, by default.

查看更多
登录 后发表回答