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

  • SEARCH
  • Home
  • 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 7890325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:19:32+00:00 2026-06-03T06:19:32+00:00

My program needs to kill a specific application. Is it possible on a stock,

  • 0

My program needs to kill a specific application. Is it possible on a stock, unrooted device? If yes – how? I know its process name and PID.

  • 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-03T06:19:33+00:00Added an answer on June 3, 2026 at 6:19 am

    Once again I am answering too late but since I run on a same situation today I thought to share my findings in order to help someone.

    First of all you need to understand what you can kill and what not. By Android’s point of view an application is not like other OSes. An Android application consists of many components (activities, broadcast receivers, services, most important tasks etc.) which are packed in a package. A package can have more that one processes running depending on its components running.

    Now the interesting part is that an android package isn’t considered (by android) killed or stopped if any or all of its processes have killed, in fact a package can still be running even with no processes running at all. You can see this effect if you start an emulator, start a program (i.e. Browser) and then kill its process via DDMS, after that go to the application’s package settings (Settings --> Applications --> Manage Applications --> All --> Browser), you can see the Force Stop button enabled, this means that the application is still running (from Android’s point of view). What happened here is that the application has one or more tasks frozen. That is, Android has saved the state of the application’s activities (task or tasks) and so the package is still running or better if the user returns to it he will land on the last thing he was doing. Now if you click the Force Stop button, Android will discard all of these frozen tasks and when the user returns to the application he will see the first activity. A Task is something you cannot kill (since froyo) only the user (from Force Stop button), the system or a third party application which is signed with the same key of the system can do that (and maybe a root capable application but I have not confirmed this). On the other hand a Process is something you can kill and reclaim the memory it uses, as long as you follow some restrictions:

    1. You have the android.permission.KILL_BACKGROUND_PROCESSES permission.
    2. The processes are not system or root processes.
    3. The process is not belonging to a component which is persistent.
    4. The process is not a critical for the system to operate by any other means.

    Besides the No. 1 rule you do not have to do something about them, Android will take care of this.

    ActivityManager has a handy function you can use in order to kill all of the processes a package has at once. When you invoke it, Android will kill any process which can be killed and thus free up some memory. However, the state of the tasks for this package will be saved and when the user returns to the application he will see the last thing he was doing unless the system itself has killed them. This can occur either because it needs resources or the state was saved long time ago (about 30 minutes). The side-effect is that because users are thinking that all applications are like in desktop operating systems, they do not believe that the application is really closed but this is the life with android.

    Now to the code:

    For my project I have prepared three functions to achieve this.

    The first one looks for the first process pid a package may have and it returns -1 if there aren’t any.

    private Context cx;
    private ActivityManager am = (ActivityManager) cx.getSystemService(Context.ACTIVITY_SERVICE);
    
    public int findPIDbyPackageName(String packagename) {
        int result = -1;
    
        if (am != null) {
            for (RunningAppProcessInfo pi : am.getRunningAppProcesses()){
                if (pi.processName.equalsIgnoreCase(packagename)) {
                    result = pi.pid;
                }
                if (result != -1) break;
            }
        } else {
            result = -1;
        }
    
        return result;
    }
    

    The second does something stupid but I need it for my project.

    public boolean isPackageRunning(String packagename) {
        return findPIDbyPackageName(packagename) != -1;
    }
    

    The third does the job.

    public boolean killPackageProcesses(String packagename) {
        boolean result = false;
    
        if (am != null) {
            am.killBackgroundProcesses(packagename);
            result = !isPackageRunning(packagename);
        } else {
            result = false;
        }
    
        return result;
    }
    

    They are confirmed to work with emulator API 8 and 9 and on a real device (Galaxy S2) with API 15 and they DO kill any application’s processes (not just your own) as long as they aren’t needed.

    Now about the android.os.Process.killProcess documentation which states that:

    … Typically this means only the process running the caller’s packages/application and any additional processes created by that app; …

    I believe that “the process running the caller’s packages/application” means the home launcher application and NOT your own application. Your application is the caller and the process running the caller’s packages/application is the home launcher or any other app launched your application. This is the only way for me to explain that the killBackgroundProcesses function and the android.os.Process.killProcess function are indeed work on third party applications.

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

Sidebar

Related Questions

My program needs to know when a user ejects cd disc. Is there some
I have a program which needs to invoke a process to perform an operation
I'm writing a program that needs to be able to kill certain processes. The
My program needs to do 2 things. Extract stuff from a webpage. Do stuff
My program needs to make use of void* in order to transport data or
My program needs to listen incoming socket connections (lets agree on port 8765), but
My C++ program needs a block of uninitialized memory and a void* pointer to
I have a program that needs several third-party libraries, and at the moment it
I have a program that needs a lot of memory and want to set
I have a program which needs to hold approximately 3000 open file descriptors in

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.