1

I am using following code to terminate background app(calculator). for that I have created a service When I am running app. It is not killing background process(calculator) Whats wrong with the code Ihave also given permission. "android.permission.KILL_BACKGROUND_PROCESSES"

  ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
                    List<ActivityManager.RunningTaskInfo> packageName = am.getRunningTasks(10);
                    // String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();
                    for (RunningTaskInfo appinfo : packageName) 
                    {
                        if((appinfo.topActivity.getPackageName().toString()).indexOf("calculator2")!= -1)
                        {
                        Log.i(Tag,""+ appinfo.topActivity.getPackageName());
                        Toast.makeText(MyService.this, ""+appinfo.topActivity.getPackageName(), Toast.LENGTH_SHORT).show();
                        am.killBackgroundProcesses(appinfo.topActivity.getPackageName());
                        }
                    }
Tushar
  • 1,122
  • 1
  • 13
  • 28
  • Your service only does this once, when it starts. If you are expecting it to happen more than one time you'll need to turn it into some kind of repeating code like a loop. – FoamyGuy Apr 17 '13 at 13:53
  • @FoamyGuy I have made some changes in code now it is showing backgroung apps but not killing it – Tushar Apr 18 '13 at 09:54
  • @Tushar can u pls tell me how u resolve ur issue ?? i m also facing same issue ? – Erum Dec 03 '14 at 06:30
  • @ErumHannan I was not able to kill process, i am now just bringing Home screen instade – Tushar Dec 09 '14 at 14:20

1 Answers1

0

refer to this answer

When we use this we do not need the "android.permission.KILL_BACKGROUND_PROCESSES" permission as well