今天在android系統下根據官方的demo代碼,我們需要啟動一個服務,並綁定,但在程序啟動以后,老是報錯:
Activity MainActivity has leaked ServiceConnection CameraUtil$
ServiceBinder@38fe0435 that was originally bound here
android.app.ServiceConnectionLeaked: Activity MainActivity has leaked ServiceConnection CameraUtil$
ServiceBinder@38fe0435 that was originally bound here
報錯信息如上,通過百度得知,出現這種MainActivity has leaked ServiceConnection,xxx was originally bound here原因,很多人說產生該異常的原因是在activity銷毀的時候,沒有調用unbindService。
於是我就在Activity的destory里面加上unbindService的代碼,發現還是報錯,因為其實我們在onstop里面已經加了unbindService,所以這個不是我們的導致該報錯的主要原因。
后面經過幾番查找,原來是因為我對程序中的需要啟動和綁定的Server沒有在AndroidManifest.xml中進行注冊,於是加上注冊代碼就OK。
轉載請注明出處:http://www.cnblogs.com/lihaiping/p/6120528.html