java.lang.IllegalArgumentException: Service not registered
首先检查一下,Service是否在AndroidManifest文件中注册。格式如下:
<service android:name=".MyService" ></service>
如果Service已经注册了,还是会报这个错误的话,可能是
- bindService没有成功,就直接unbindService;
- 也可能是已经unbindService成功了,还多次进行unbindService。
解决方法:
每次绑定服务时,用一个布尔值记状态为true,
解除绑定服务时,检验布尔值是否为true,如果是true,就解除服务,并把布尔值设为false,
这样即使多次解除服务,也不会报“service not registered”了。
示例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|