Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:59:41+00:00 2026-06-03T14:59:41+00:00

Im trying to write a simple task killer. I know I shouldnt kill tasks

  • 0

Im trying to write a simple task killer. I know I shouldnt kill tasks in Android, but Im eager to try something like this. I have the following code:

List<RunningAppProcessInfo> procInfo = activityManager.getRunningAppProcesses();
for (int i = 0; i < procInfo.size(); i++) {
    Log.v("proces " + i,procInfo.get(i).processName + " pid:" + procInfo.get(i).pid + " importance: " + procInfo.get(i).importance + " reason: " + procInfo.get(i).importanceReasonCode);
    //First I display all processes into the log
}
for (int i = 0; i < procInfo.size(); i++) {
    RunningAppProcessInfo process = procInfo.get(i);
    int importance = process.importance;
    int pid = process.pid;
    String name = process.processName;
    if (name.equals("manager.main")) {
        //I dont want to kill this application
        continue;
    }
    if (importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
        //From what I have read about importances at android developers, I asume that I can safely kill everithing except for services, am I right?
        Log.v("manager","task " + name + " pid: " + pid + " has importance: " + importance + " WILL NOT KILL");
        continue;                       
    }
    Log.v("manager","task " + name + " pid: " + pid + " has importance: " + importance + " WILL KILL");
    android.os.Process.killProcess(procInfo.get(i).pid);
}   
procInfo = activityManager.getRunningAppProcesses();
//I get a new list with running tasks
for (int i = 0; i < procInfo.size(); i++) {
    Log.v("proces after killings" + i,procInfo.get(i).processName + " pid:" + procInfo.get(i).pid + " importance: " + procInfo.get(i).importance + " reason: " + procInfo.get(i).importanceReasonCode);
}

My problem here is that when I perform this code, I first get the list of all tasks, thats ok. Than I see in the log several lines of:

Sending signal. pid: (processId) SIG: 9

I asume thats a signal to die. But at the end of my code, when I display all running processes, the list is the same as before, no task has been killed. Any ide why? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:59:42+00:00Added an answer on June 3, 2026 at 2:59 pm

    You can’t kill other tasks that way because the Kernel will enforce permissions. Try this instead:

    ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
    activityManager.restartPackage(packageName);
    

    you will need the following permissions in the manifest:

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

    EDIT:

    Actually restartPackage is deprecated. use killBackgroundProcesses() instead!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to write a few simple macros to simplify the task of setting
I'm trying to write a simple task using Maven: <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <executions> <execution>
I'm trying to do something that I think should be fairly simple but I've
I'm trying to write application for Android to access Google Tasks. I decided to
I'm trying to write simple proxy server for some purpose. In it I use
I trying to write a simple function to call unmanaged code from managed code.
I'm trying to write a simple AppleScript to do some text manipulation on the
I am trying to write a simple tool using Shoes. This will indent code
I am trying to write a simple program to open a socket channel to
I'm trying to write a simple Vim function that takes the name of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.