Click here to Skip to main content
15,667,078 members
Articles / Mobile Apps / Android
Posted 28 Oct 2015

Tagged as


4 bookmarked

Android - List and Kill Background Process

Rate me:
Please Sign up or sign in to vote.
4.29/5 (6 votes)
28 Oct 2015CPOL
Android OS is a multitasking operating, there are a lot of running background process, these process make your device will be slower.


Android OS is a multitasking operating system, there are a lot of running background process, these process make your device slower. Android SDK provides a set of API that allow a developer to list all background processes and kill (stop) them. In this post, we will discuss about how to list and kill background process in Android device.


Known android App GUI and thread


We need two permissions - KILL_BACKGROUND_PROCESSES and  GET_TASKS.
Declare two permission as:

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

Declare 2 variables:

List<ActivityManager.RunningAppProcessInfo> processes;
ActivityManager amg;

Register service with Android to get all running processes:

// using Activity service to list all process
amg = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
// list all running process
processes = amg.getRunningAppProcesses();

Create MyAdapter class extends BaseAdapter class to populate process's information on ListView as:

public class MyAdapter extends BaseAdapter {

    List<ActivityManager.RunningAppProcessInfo> processes;
    Context context;

    public MyAdapter(List<ActivityManager.RunningAppProcessInfo> 
    	processes, Context context) {
        this.context = context;
        this.processes = processes;

    public int getCount() {
        return processes.size();

    public Object getItem(int position) {
        return processes.get(position);

    public long getItemId(int position) {
        return processes.get(position).pid;

    public View getView(int position, View convertView, ViewGroup parent) {

        Process pro;

        if(convertView == null)
            convertView = new TextView(context);
            pro = new Process();
   = (TextView)convertView;

            pro = (Process)convertView.getTag();

        return convertView;

    class Process
        public TextView name;

Display list of process on listview, display name only (just demo).

adp = new MyAdapter(processes, MainActivity.this);

When user longclicks on process name, this process will be killed:

lst.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    public boolean onItemLongClick(AdapterView<?> 
    	parent, View view, int position, long id) {
        if (load == 1) {
            for (ActivityManager.RunningAppProcessInfo info : processes) {
                if (info.processName.equalsIgnoreCase(
				(position)).processName)) {
                    // kill selected process
                    android.os.Process.sendSignal(, android.os.Process.SIGNAL_KILL);
            load = 0;
            // refresh list of process
        return true;

You can only kill user process, with system process you need a rooted device.

Points of Interest

This is a very simple tip for killing running background processes on Android.


  • Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Team Leader Tae Kwang Can Tho LTD
Vietnam Vietnam
Code for fun -> ^.^ <-

Comments and Discussions

PraiseGood example code Pin
Member 1376026221-May-18 9:47
Member 1376026221-May-18 9:47 
GeneralFine on Android 4.0.3 - 4.4.2 Pin
Member 1376026221-May-18 9:53
Member 1376026221-May-18 9:53 
Questionprocesses = amg.getRunningAppProcesses(); Pin
catalystOne Dupinder1-Jun-16 5:28
catalystOne Dupinder1-Jun-16 5:28 
AnswerRe: processes = amg.getRunningAppProcesses(); Pin
Member 60234608-Mar-18 22:42
Member 60234608-Mar-18 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.