How can I programmatically force stop an Android app with Java?
get the process ID of your application, and kill that process onDestroy() method
@Override
public void onDestroy()
{
super.onDestroy();
int id= android.os.Process.myPid();
android.os.Process.killProcess(id);
}
or
getActivity().finish();
System.exit(0);
and if you want to kill other apps from your activity, then this should work
You can send the signal using:
Process.sendSignal(pid, Process.SIGNAL_KILL);
To completely kill the process, it's recommended to call:
ActivityManager.killBackgroundProcesses(packageNameToKill)
before sending the signal.
Please, note that your app needs to own the KILL_BACKGROUND_PROCESSES permission. Thus, in the AndroidManifest.xml, you need to include:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Try to use following code
finish(); // for stopping Current Activity
// add this line for Removing Force Close
@Override
protected void onDestroy() {
// closing Entire Application
android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();
}
}
May be this solution will help you Force Close an app programmatically