-4

I am building an application that should be able to close other android applications. In this case, I am using Google Maps. I have granted permission in the Android Manifest XML to killBackgroundProcesses, but the following code does not close the "Google Maps" application. My app calls killApp() every second to ensure Google Maps is closed. Any idea what I'm doing wrong here?

    public void KillApp()
    {
        Context context = getContext();
        String maps =  "com.google.android.apps.maps";
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.killBackgroundProcesses(maps);
    }
Shabina Rayan
  • 389
  • 1
  • 8
  • 22

1 Answers1

0

You can only kill your own apps, e.g. the ones running in the same process or with the same userID. You can not kill others, unless the device is rooted.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.

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • According to the docs restartPackage() is deprecated and just wraps the killBackgroundProcesses() method starting SDK 15 – Alexey Ozerov Apr 19 '20 at 05:43