我需要强制关闭另一个应用程序而不自动重启它。
我尝试下一步,应用程序将关闭,但几秒钟后应用程序自动重启(我认为这是系统保护任何应用程序的崩溃):
// 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) {}
但是杀死了应用程序的自重启。请告诉我有关在不重新启动的情况下强制停止另一个应用程序的任何想法。