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());
}
}