0

In my app, there is a service checking for incoming audio calls (through internet). I am facing that the service has been killed by the OS after sometime being idle, but the notification icon appears like the service is running and in phone settings its displaying that the service is currently running. I found some apps on google play where service is not killed even on low memory.

I added START_STICKY to restart it when it is stopped. I also made it to run as foreground.

I want my service not to be killed. May I know the procedure for it. (If the service is killed, it should reflect in the notification and in phone settings).

Sri
  • 85
  • 2
  • 10
  • can you post the code of the service? – Aegis Oct 12 '15 at 11:54
  • call your service in its onStartMethod(), to continously call it, but call it within handler or alarm manager to manage some time duration gap between two calls. – Androider Oct 12 '15 at 11:55
  • Possible duplicate of [How can we prevent a Service from being killed by OS?](http://stackoverflow.com/questions/9696861/how-can-we-prevent-a-service-from-being-killed-by-os) – Jonas Czech Oct 12 '15 at 11:56
  • 1
    *I want my service not to be killed* you can not 100% avoid the OS killing your service – Tim Oct 12 '15 at 11:59

1 Answers1

1

Having read this question, immediately want to refer you to a blog post, which really helped me to understand how android achieves multitasking, and where services fit into this context.

"http://android-developers.blogspot.com/2010/04/multitasking-android-way.html"

But, to summarize, there is no way to truely prevent being killed, and, when android decides it needs to reclaim memory, "it will do so brutally, simply killing the process" that this service resides in.

So, two things - first, you have to develop your application so that in the event of this service being killed, it will recover. There is no way to truely guarantee this won't happen.

Secondly, you should minimize the likelihood of this occuring by responding to memory events - documented here:

http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)

Basically, you can develop your application to be notified when Android is about to start killing processes, and when you receive that notification, respond by freeing up memory.

Ev0xFrost
  • 56
  • 3