- Hardware alarm event
- AlarmManagerService
- Your application components to handle alarms
For devices running Android 2.1 and below, the method the task killer uses to kill an application is ActivityManager.restartPackage(String) that in turn triggers the UninstallReceiver defined in AlarmManagerService to remove all links registered by your application.
class UninstallReceiver extends BroadcastReceiver { public UninstallReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_RESTARTED); // <------ this line filter.addDataScheme("package"); mContext.registerReceiver(this, filter); } @Override public void onReceive(Context context, Intent intent) { synchronized (mLock) { Uri data = intent.getData(); if (data != null) { String pkg = data.getSchemeSpecificPart(); removeLocked(pkg); mBroadcastStats.remove(pkg); } } } }
But, in Android 2.2, things changed. The restartPackage method is changed to be just a wrapper of a new method killBackgroundProcesses. So, task killers on the Market are doing the same thing as default Out-Of-Memory (OOM) killer. Although we can still install them to proactively kill processes, but they are not necessary any more.