0

I have developed a simple background service, which tries to prove self resistance when app is killed. For this purpose I return in onStartCommand - START_STICKY - obvious !

When I'm testing killing service's process either:

  1. from Application Settings -> Force Stop
  2. or under Eclipse DDMS perspective Stop Process...

I noticed that in the 1st scenario the service is never restarted. On the other hand in the 2nd scenario the service is re-created and onCreate method is called...

Why it is like that? Any differences in killing processes by these two approaches?

damax
  • 453
  • 1
  • 5
  • 18
  • I'm not sure Eclipse kills it unless used from the DDMS, if used from DDMS they're the same. – Shark Jul 11 '13 at 11:34
  • Perhaps, `Force Stop` does what it's intended to do and simply calls `onStop()` while eclipse kills the PID and probably ensures an `onDestroy()` call in itself... Never really noticed the difference until you mentioned it now. – Shark Jul 11 '13 at 11:34

1 Answers1

1

Any differences in killing processes by these two approaches?

Yes. In DDMS, "Stop Process" kills the process. With "Force Stop", not only is the process killed, but it is moved into the "stopped" state, where nothing in that app will run again until somebody manually runs one of that app's components (typically: the user launches an activity from the home screen).

You can read more about the stopped state in the Android 3.1 documentation.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Glad to hear I wasn't far off. – Shark Jul 11 '13 at 12:11
  • what about situation, when Android will try to get rescue some memory and will kill app process? Will START_STICKY re-create the service? According my understanding, yes. If so, it means that in such situations the killed app is not in stopped state and behaves as the process would be killed from DDMS. – damax Jul 11 '13 at 12:39
  • @damax: "Will START_STICKY re-create the service? According my understanding, yes" -- yes, though the timing may not be immediate. "If so, it means that in such situations the killed app is not in stopped state and behaves as the process would be killed from DDMS" -- correct. An even better way to simulate low memory is to swipe your app off the recent-tasks list on Android 4.0, or to use a third-party task manager. Those will use a particular API which is advertised as behaving just like the low-memory logic. – CommonsWare Jul 11 '13 at 12:44