强制关闭其他应用,可以使用ActivityManager,首先需要获取(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
然后可以调用其函数来进行关闭操作,目前来看有两种方法:
1. void killBackgroundProcesses(String packageName):此方法在android官网的API中有介绍,在kill之后,被关闭的应用会被重新启动。
Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.
使用:需要权限:
2. void forceStopPackage(String packageName):此方法目前没有出现在android官网的API中,不知为何啊。。。。。。
使用:
需要权限:android:sharedUserId="android.uid.system"
自己实现的代码:
ActivityManager activityManager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
activityManager.forceStopPackage("com.android.scan");
推荐使用第2种。。。。。。。。。。。。。
原文:http://www.cnblogs.com/luow/p/3885349.html