我有一个活动A,单击按钮后,我正在启动另一个活动B,其中我将使用bindService
来启动服务,如下所示:
Intent intent = new Intent(context, RadioService.class);
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
在此期间,服务类的onCreate()
被调用。现在,当我关闭B的onDestroy()
内的活动B时,将停止服务,如下所示:
context.unbindService(serviceConnection);
我遇到的问题是第二次,如果我进入活动B,则服务类onCreate()
没有被调用。为什么会这样呢?我希望调用onCreate()
可以做什么?
答案 0 :(得分:0)
我通过在startService()
之前调用bindService()
解决了这个问题。