0

我需要强制关闭另一个应用程序而不自动重启它。

我尝试下一步,应用程序将关闭,但几秒钟后应用程序自动重启(我认为这是系统保护任何应用程序的崩溃):

// 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) {}

但是杀死了应用程序的自重启。请告诉我有关在不重新启动的情况下强制停止另一个应用程序的任何想法。

4

1 回答 1

2

因为你有 root 权限,你可以尝试 adb 命令来停止应用程序:

adb shell am force-stop APP_PACKAGE
于 2013-06-21T07:08:40.130 回答