强制关闭其他应用,可以使用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.
使用:需要权限:<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
2. void forceStopPackage(String packageName):此方法目前没有出现在android官网的API中,不知为何啊。。。。。。
使用:
需要权限:android:sharedUserId="android.uid.system"
<uses-permission android:name="android.permission.FOCE_STOP_PACKAGES" />
自己实现的代码:
ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
activityManager.forceStopPackage("com.android.scan");
推荐使用第2种。。。。。。。。。。。。。
参考:http://blog.csdn.net/huxueyan521/article/details/8921976
http://blog.csdn.net/mingli198611/article/details/7057615