2

I've got an activity that launches a local service using the bindService() method. Everything works great while the app is running, but when I terminate the app and unbind from the service in the activity's onDestroy(), several seconds later I see the following errors show up in 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

Not quite sure what's going on here considering both the activity and the service have terminated (onDestroy() has executed in both). I'm guessing there's still a thread running somewhere? The service does create and use the Android MediaPlayer.

Mike Lowery
  • 2,630
  • 4
  • 34
  • 44
  • Have you solved it? If yes, could you please update with your solution? If not - check what your service's onUnbind() returns. When I set it to return false then it works Ok, but if true then I get ANR. However I am out ot ideas why returning false fixes it for me. I wish I could get a clear understanding. – Vit Khudenko Oct 21 '10 at 20:34

2 Answers2

4

I was also receiving the ANR message after a service terminated.

My problem was that the application's main activity was calling "bindService()" twice - once before "startService()" and once afterwards.

Removing either of the calls to bindService() solved the problem.

user621267
  • 56
  • 3
  • Looking at my code, I'm only calling bindService in the application's OnCreate and onResume methods (and only if it's null). – Mike Lowery Feb 19 '11 at 18:32
  • Ok I think I found the ANR problem. The variable for my service isn't set until onServiceConnected fires, so the check for null wasn't working correctly in onResume. I took out the bindService from onResume altogether and now there is no more ANR. However, I'm finding that my service is still getting destroyed and re-created whenever my application is paused and resumed (e.g. screen rotation). Is this an artifact of using BIND_AUTO_CREATE? I don't want my service to be destroyed until my application is destroyed. – Mike Lowery Feb 19 '11 at 23:48
0

As a new dev myself this happened to me but I'm not quite sure how I solved it. I think it had something to do with the the binding to the service. As per Google's documentation, whenever you bind to a service, the service starts automatically IF you use the BIND_AUTO_CREATE flag in your bindService command. Not wanting my service to start automatically whenever it felt like it I just didn't use the BIND_AUTO_CREATE flag and I THINK that fixed it.

Again, I could be completely wrong but this is something to try.

ShadowGod
  • 7,891
  • 3
  • 28
  • 31