如何强行停止应用程序编程,机器人 [英] How to force-stop the application programatically-Android
本文介绍了如何强行停止应用程序编程,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的Android应用程序强行停止应用程序,(而不是由人手工做的apps->强制停止)。如何实现这一点。
I want to force-stop an application from my android app, (Instead of doing manually by Man apps->force-stop). How to achieve this.
推荐答案
使用此实现findout进程ID和杀死它。
Use this implementation to findout the process id and kill it.
int pid;
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
for(int i = 0; i < pids.size(); i++)
{
ActivityManager.RunningAppProcessInfo info = pids.get(i);
if(info.processName.equalsIgnoreCase("com.yourapp.app")){
pid = info.pid;
}
}
android.os.Process.killProcess(pid);
这篇关于如何强行停止应用程序编程,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文