我有一个使用bindService()方法启动本地服务的活动。应用程序运行时一切正常,但是当我终止应用程序并在活动的onDestroy()中取消绑定时,几秒钟后我看到logcat中出现以下错误:
09-25 02:13:46.035: WARN/ActivityManager(60): Timeout executing service: ServiceRecord{4401dfc0 net.kicksass.shootingstarbbs.streamstar/.StreamStarService}
09-25 02:13:46.055: INFO/Process(60): Sending signal. PID: 285 SIG: 3
09-25 02:13:46.055: INFO/dalvikvm(285): threadid=3: reacting to signal 3
09-25 02:13:46.103: INFO/dalvikvm(285): Wrote stack traces to '/data/anr/traces.txt'
09-25 02:13:46.103: INFO/Process(60): Sending signal. PID: 60 SIG: 3
09-25 02:13:46.103: INFO/dalvikvm(60): threadid=3: reacting to signal 3
09-25 02:13:46.203: INFO/dalvikvm(60): Wrote stack traces to '/data/anr/traces.txt'
...
09-25 02:13:46.683: ERROR/ActivityManager(60): ANR in net.kicksass.shootingstarbbs.streamstar
09-25 02:13:46.683: ERROR/ActivityManager(60): Reason: Executing service net.kicksass.shootingstarbbs.streamstar/.StreamStarService
09-25 02:13:46.683: ERROR/ActivityManager(60): Load: 3.08 / 1.16 / 0.41
09-25 02:13:46.683: ERROR/ActivityManager(60): CPU usage from 21237ms to 43ms ago:
09-25 02:13:46.683: ERROR/ActivityManager(60): rbbs.streamstar: 7% = 4% user + 2% kernel / faults: 4967 minor 14 major
09-25 02:13:46.683: ERROR/ActivityManager(60): system_server: 3% = 2% user + 1% kernel / faults: 434 minor 8 major
09-25 02:13:46.683: ERROR/ActivityManager(60): com.svox.pico: 1% = 0% user + 0% kernel / faults: 2817 minor 1 major
09-25 02:13:46.683: ERROR/ActivityManager(60): adbd: 0% = 0% user + 0% kernel
09-25 02:13:46.683: ERROR/ActivityManager(60): ndroid.launcher: 0% = 0% user + 0% kernel / faults: 353 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): m.android.phone: 0% = 0% user + 0% kernel / faults: 187 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): putmethod.latin: 0% = 0% user + 0% kernel / faults: 151 minor 1 major
09-25 02:13:46.683: ERROR/ActivityManager(60): .quicksearchbox: 0% = 0% user + 0% kernel / faults: 115 minor 1 major
09-25 02:13:46.683: ERROR/ActivityManager(60): m.android.email: 0% = 0% user + 0% kernel / faults: 140 minor 1 major
09-25 02:13:46.683: ERROR/ActivityManager(60): kswapd0: 0% = 0% user + 0% kernel
09-25 02:13:46.683: ERROR/ActivityManager(60): logcat: 0% = 0% user + 0% kernel / faults: 6 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): ndroid.settings: 0% = 0% user + 0% kernel / faults: 118 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): d.process.acore: 0% = 0% user + 0% kernel / faults: 90 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): id.defcontainer: 0% = 0% user + 0% kernel / faults: 103 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): m.android.music: 0% = 0% user + 0% kernel / faults: 109 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): d.process.media: 0% = 0% user + 0% kernel / faults: 110 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): com.android.mms: 0% = 0% user + 0% kernel / faults: 121 minor 1 major
09-25 02:13:46.683: ERROR/ActivityManager(60): events/0: 0% = 0% user + 0% kernel
09-25 02:13:46.683: ERROR/ActivityManager(60): roid.alarmclock: 0% = 0% user + 0% kernel / faults: 102 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): android.protips: 0% = 0% user + 0% kernel / faults: 102 minor
09-25 02:13:46.683: ERROR/ActivityManager(60): TOTAL: 7% = 3% user + 3% kernel + 0% iowait
考虑到活动和服务都已终止(onDestroy()已在两者中执行),不太确定这里发生了什么。我猜测还有一个线程在哪里运行?该服务确实创建并使用Android MediaPlayer。
答案 0 :(得分:4)
服务终止后,我也收到了ANR消息。
我的问题是应用程序的主要活动是两次调用“bindService()” - 一次在“startService()”之前和之后一次。
删除对bindService()的任何一个调用都解决了这个问题。
答案 1 :(得分:0)
作为一个新的开发者,我发生了这件事,但我不太确定我是如何解决它的。我认为它与绑定服务有关。根据Google的文档,无论何时绑定到服务,如果在BIND_AUTO_CREATE
命令中使用bindService
标志,服务都会自动启动。不希望我的服务在感觉到它的时候自动启动我只是没有使用BIND_AUTO_CREATE
标志而且我认为修复了它。
同样,我可能完全错了,但这是值得尝试的。