I am working on alarm ,which works most of the time but sometime it does not works.Then I found that it will work until your application has not been killed or device has been rebooted.I am not rebooting my device so only reason could be that my app is being killed. So my question is based on what condition and criteria Android itself kills my app.
-
Normally it happens on Low memory.. – Pankaj Kumar Nov 07 '13 at 06:17
-
@PankajKumar is there any way to know when my app is killed – Shakeeb Ayaz Nov 07 '13 at 06:19
-
I am not sure but http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int) can catch the same.. – Pankaj Kumar Nov 07 '13 at 06:22
-
1I have given http://stackoverflow.com/questions/5916859/how-to-save-alarm-after-app-killing as link on your another question. This must solve your problem... Logic is that to handle onDestroy of a Service... onDestroy will call when OS kills our application.. so you can handle that method to know about your application hass been killed... – Pankaj Kumar Nov 07 '13 at 06:25
3 Answers
According to the doc
Android might decide to shut down a process/app at some point, when memory is low and required by other processes that are more immediately serving the user. Application components running in the process that's killed are consequently destroyed. A process is started again for those components when there's again work for them to do.
When deciding which processes to kill, the Android system weighs their relative importance to the user. For example, it more readily shuts down a process hosting activities that are no longer visible on screen, compared to a process hosting visible activities. The decision whether to terminate a process, therefore, depends on the state of the components running in that process.
The link below will help you to understand this:
http://developer.android.com/guide/components/processes-and-threads.html
You can make you service to run in foreground so that it wont be killed by system. Music player is one such example.

- 8,250
- 3
- 39
- 71
Simple answer is "On low memory"...
Android might decide to shut down a process at some point, when memory is low and required by other processes that are more immediately serving the user. Application components running in the process that's killed are consequently destroyed. A process is started again for those components when there's again work for them to do.
When deciding which processes to kill, the Android system weighs their relative importance to the user. For example, it more readily shuts down a process hosting activities that are no longer visible on screen, compared to a process hosting visible activities. The decision whether to terminate a process, therefore, depends on the state of the components running in that process. The rules used to decide which processes to terminate is discussed below.
Read more about processes-and-threads and read How to save Alarm after app killing?

- 1
- 1

- 81,967
- 29
- 167
- 186