[英]How force close another application
I need force close another application without autorestart it. 我需要强制关闭另一个应用程序而无需自动重启它。
I try next steps, application will closed but after few seconds application autorestart (I think this is system protection any applications for craches): 我尝试下一步,应用程序将关闭,但几秒后应用程序autorestart(我认为这是系统保护任何应用程序的craches):
// try 1
try
{
Method forceStopPackage;
ActivityManager activityManager = ((ActivityManager)contextService.getSystemService( Context.ACTIVITY_SERVICE));
forceStopPackage = activityManager.getClass().getDeclaredMethod( "forceStopPackage", String.class);
forceStopPackage.setAccessible( true);
forceStopPackage.invoke( activityManager, sApplicationPackageName);
}
catch( Exception e) {}
// try 2
Process localProcessKill = null;
DataOutputStream localDataOutputStreamKill = null;
DataInputStream localDataInputStreamKill = null;
try
{
localProcessKill = Runtime.getRuntime().exec( "su");
localDataOutputStreamKill = new DataOutputStream( localProcessKill.getOutputStream());
localDataInputStreamKill = new DataInputStream( localProcessKill.getInputStream());
if( (localDataOutputStreamKill != null) && (localDataInputStreamKill != null))
{
localDataOutputStreamKill.writeBytes( "kill -9 " + processInfo.pid + "\n");
localDataOutputStreamKill.flush();
localDataOutputStreamKill.writeBytes( "exit\n");
localDataOutputStreamKill.flush();
// localProcessKill.waitFor();
}
}
catch( Exception e) {}
// try 3
try
{
activityManager.killBackgroundProcesses( processInfo.processName);
}
catch( Exception e) {}
// try 4
try
{
android.os.Process.sendSignal( processInfo.pid, android.os.Process.SIGNAL_KILL);
}
catch( Exception e) {}
But killed application self- restarting. 但杀死的应用程序自动重启。 Please get me any ideas about force stop another application without restarting.
请告诉我有关强制停止其他应用程序而不重新启动的任何想法。
由于您具有root权限,因此可以尝试使用adb命令停止应用:
adb shell am force-stop APP_PACKAGE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.