android service startService() and bindService()

前端 未结 3 828
别跟我提以往
别跟我提以往 2020-11-30 23:45

I would like to know if it is possible to have a service that is started with startService and then be able to also bind to that service and do some remote procedure calls?

3条回答
  •  长情又很酷
    2020-12-01 00:30

    I think hara's answer was a little confusing. What you describe is perfectly legitimate and in fact the only way to get the behavior you want. If you create a Service by binding to it, it will die when you unbind. So the only way to keep it around without activities binding to it is to start it with startService(). There is no conflict with lifecycles because it only applies to how the service is STARTED. So once it's started with startService(), it follows that lifecycle process. So you are free to bind and unbind to it as much as you wish and it will only die when you call stopService() or stopSelf().

提交回复
热议问题