Reputation: 4857
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):
// 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.
Upvotes: 0
Views: 512
Reputation: 116322
since you have root permission, you can try the adb command for stopping an app:
adb shell am force-stop APP_PACKAGE
Upvotes: 2