使用forcestoppackge结束后台进程
使用killBackgroundProcesses只能杀死进程不能杀死服务,在网上搜集的资料 可以用forcestoppackge完全杀死进程,
使用forcestoppackge结束后台进程时抛异常,至使无法结束进程,
添加了android.permission.FORCE_STOP_PACKAGES权限
也获取了系统权限android:sharedUserId="android.uid.system"
求大神指导
部分代码如下:
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
try
{
Method forceStopPackage = activityManager.getClass().getMethod("forceStopPackage", String.class);
forceStopPackage.setAccessible(true);
forceStopPackage.invoke(activityManager, "com.android.browser");
} catch (NoSuchMethodException e)
{
e.printStackTrace();
}catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (IllegalArgumentException e)
{
e.printStackTrace();
} catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
执行至forceStopPackage.invoke()方法时抛出 InvocationTargetException 异常