Android – List and kill background process

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

List all android background processes
List all android background processes

We need two permission are KILL_BACKGROUND_PROCESSES and to 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 variable

List<ActivityManager.RunningAppProcessInfo> processes;
ActivityManager amg;

Register service with Android 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 extend 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 longclick on process name, this process will be kill

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(
                        ((ActivityManager.RunningAppProcessInfo)parent.getItemAtPosition(position)).processName)) {
                    // kill selected process
                    android.os.Process.sendSignal(, android.os.Process.SIGNAL_KILL);
            load = 0;
            // refresh list of process
        return true;

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

Ok, download sourcecode Here


Phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập: Logo

Bạn đang bình luận bằng tài khoản Đăng xuất /  Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất /  Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất /  Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất /  Thay đổi )


Connecting to %s