0
我需要強制關閉另一個應用程序而無需自動重啓它。如何強制關閉另一個應用程序
我試試下面的步驟,應用程序將關閉,但幾秒鐘自動重啓動應用後(我認爲這是系統保護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) {}
但殺死的應用自重新啓動。 請給我任何關於強制停止另一個應用程序而不重新啓動的想法。