How to be notified when external process is killed?

Get notified when a process end or is killed on Android

  • I've been digging the web in quest of finding nice, androidish solution for this concrete problem, but havent found one, so here I am, posting my first question on StackOverflow. To elaborate on my problem, I have a full-fledged aidl service, to which some other processes bind. My service will allocate some resources for each of process connecting to it, and I want to make this statement bold, the resource allocation is made for process, I make some kind of a session tracking, where getCallingPid() and getCallingUid() play a role of session identifiers. So the problem here is that Android will never tell us if an application which was bound to us went away for some reason, so the system resources allocated for that destroyed process would be wasted away by being held by our service. One solution that I found somewhat feasible is just to poll http://developer.android.com/reference/android/app/ActivityManager.html#getRunningAppProcesses%28%29 and calculate set difference between current and previous snapshots, but this method looks really dirty. Could anyone suggest some better method to do this? I'd be really grateful! Thanks, Giorgi

  • Answer:

    As far as I'm aware, Android won't tell you when processes are killed. I suspect the only method is to get a list of running applications every x seconds or minutes, and keep track of the applications that way. I think this is what you already suggested in the question as well. It's not pretty, but it's likely one of the only ways to do it.

Giorgi at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.