[英]Service onCreate() is not being called
I have a activty A and after a button click I am starting another activity B in which I am starting a service using bindService
as below:我有一个活动 A,单击按钮后,我正在启动另一个活动 B,在该活动中我使用
bindService
启动服务,如下所示:
Intent intent = new Intent(context, RadioService.class); context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
During this the onCreate()
of the service class is being called.在此期间,正在调用服务类的
onCreate()
。 Now when I close the activity B inside onDestroy()
of BI am stopping the service as below:现在,当我关闭 BI 的
onDestroy()
中的活动 B 时,将停止服务,如下所示:
context.unbindService(serviceConnection);
The problem that I am facing is second time if I enter the activity B the service class onCreate()
is not being called.我面临的问题是第二次,如果我进入活动 B,则不会调用服务类
onCreate()
。 Why is so that the case?为什么会这样? What can be done as I want the
onCreate()
to be called.我想要调用
onCreate()
可以做什么。
我通过在bindService()
之前调用startService()
来解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.