top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android: Kill other process

+1 vote
410 views

There are some apps out there for android that can improve mobile/tablet performance by killing the applications that run in background. How to do that?

posted Sep 8, 2016 by Vijay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

With PackageManager you can access all the installed packages and you can request system to kill the background process by ActivityManager. Here is a working code snippet.

List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
packages = pm.getInstalledApplications(0); //get a list of installed apps.

ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);

for (ApplicationInfo packageInfo : packages) {
    if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1) continue; // Exclude system packages
    if(packageInfo.packageName.equals("mypackage")) continue; // Exclude your packages/application
    mActivityManager.killBackgroundProcesses(packageInfo.packageName);
}  

Update:
These permissions must be requested,

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.GET_TASKS" />

Hope this helps!

answer Sep 9, 2016 by Vinod Kumar K V
Similar Questions
+2 votes

I am developing an android application and I want my app to be able to receive data from other apps. How can I do that?

0 votes

I'm looking for the equivalent of a rc0.d script to take down Android in a clean way so that it can be restarted. In my usecase, Android is running within a jailed chroot for reasons I can't go into great detail about. However, I would like the ability to essentially kill all of the Android services and relaunch on command.
I cannot/will not be using the standard Android dialogs for much and don't want to use the power-off dialog or anything.
I have done some searches and they've all lead me to the ShutdownThread.java file which sends the INTENT_SHUTDOWN to stop a couple of services and then either reboots or shuts down the phone. I only want the first part with no action taken on the device itself (not that it would do much in my case anyway)..

...