简体   繁体   中英

finish or close an application from another application

I want to know, is it possible to finish or close an running application from my application? If yes then how ?

I googled regarding this but not found any solution. I tried using killBackgroundProcesses but it also not worked for me. The functionality what I am expecting something like Task Manager is doing. Please suggest me some thing. Thanks in advance.

No one can kill process except Android OS itself.

Most of the task killer in android market don't kill the app they just restart the process

by using

public void restartPackage (String packageName) when this method is called by your activity the operating system immediately called

savedInstanceState and save the state of that activity you want to kill. Now this process is

removed from memory and OS saved it state.Now when next time user start that activity it

will start from where it was killed or in other words restarted. You can verify it from any

task manager that they don't kill the process because no one can do so. This method also

work in ICS.

for above method you can look at here . As far as i know killBackgroundProcesses (String packageName) is for API 8 and above.

First, you need a pid of process. You can get it for the package name like in this code:

ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
             int processid = 0;
       for(int i = 0; i < pids.size(); i++)
       {
           ActivityManager.RunningAppProcessInfo info = pids.get(i);
           if(info.processName.equalsIgnoreCase("here your package name")){
              processid = info.pid;
           } 
       }

Then you can use killProcess function for terminate process with specified pid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM