1

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.

maddy d
  • 1,530
  • 2
  • 12
  • 23
  • maybe this post can help you: http://stackoverflow.com/questions/19860053/close-activity-from-another-activity-through-an-intent – Ozan Aug 18 '14 at 09:47
  • @ozi I want to close main activity(launcher activity) from other application. – maddy d Aug 18 '14 at 10:08

2 Answers2

1

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.

vishal arote
  • 126
  • 2
0

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.

anil
  • 2,083
  • 21
  • 37