Android异常:ServiceConnection 泄露

写了个service,用来播放提示音,当用户没有去处理并且提示音播放完毕的时候,发送一条Notification执行onDestory()方法,这个时候是直接销毁的方法,并没有调用unbindService去释放服务连接,那么就会出现 ServiceConnection 泄露的情况,虽然说不会影响程序的正常运行,但是还是解决掉比较好。

解决办法就是使用unbindService 解除绑定,限于我的特定情况,我在Activity中动态注册了一个广播接收器,然后在Service中当提示音播放完毕的时候发送一条广播,在Activity中接收,解除和Service的绑定。

有时间把整个程序弄到博客上来做个记录。//TODO

04-18 11:01:02.270 440-440/css.alarm.com.alarmdemo E/ActivityThread: Activity css.alarm.com.alarmdemo.PlayAlarmActivity has leaked ServiceConnection css.alarm.com.alarmdemo.PlayAlarmActivity$1@42efa448 that was originally bound here
                                                                     android.app.ServiceConnectionLeaked: Activity css.alarm.com.alarmdemo.PlayAlarmActivity has leaked ServiceConnection css.alarm.com.alarmdemo.PlayAlarmActivity$1@42efa448 that was originally bound here
                                                                         at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:979)
                                                                         at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)
                                                                         at android.app.ContextImpl.bindServiceAsUser(ContextImpl.java:1833)
                                                                         at android.app.ContextImpl.bindService(ContextImpl.java:1821)
                                                                         at android.content.ContextWrapper.bindService(ContextWrapper.java:503)
                                                                         at css.alarm.com.alarmdemo.PlayAlarmActivity.initView(PlayAlarmActivity.java:153)
                                                                         at css.alarm.com.alarmdemo.PlayAlarmActivity.onCreate(PlayAlarmActivity.java:47)
                                                                         at android.app.Activity.performCreate(Activity.java:5372)
                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
                                                                         at android.app.ActivityThread.access$700(ActivityThread.java:159)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                         at android.os.Looper.loop(Looper.java:176)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5419)
                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                         at java.lang.reflect.Method.invoke(Method.java:525)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
                                                                         at dalvik.system.NativeStart.main(Native Method)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值