1.使用killBackgroundProcesses()方法
首先再AndroidManifest.xml文件中添加权限
然后直接调用stopApp(mContext,packageName)方法
public void stopAppByKill(Context context ,String packageName) {
ActivityManager mActivityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
mActivityManager.killBackgroundProcesses(packageName);
2.forceStopPackage()方法
该方法属于隐藏方法,需要使用反射机制调用,同样需要在AndroidManifest.xml文件中添加权限并且要先在application中加入android:sharedUserId="android.uid.system"系统级权限才可以调用隐藏方法
然后使用反射机制调用方法
public void stopAppByForce(Context context ,String packageName) {
ActivityManager mActivityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
Method method = null;
try {
method = Class.forName("android.app.ActivityManager").getMethod("
最后
以上就是英勇冰淇淋最近收集整理的关于android终止一个进程的方法,Android根据包名停止其他应用程序的方法的全部内容,更多相关android终止一个进程内容请搜索靠谱客的其他文章。
发表评论 取消回复