我想在我的Android应用中强制停止一个应用程序,(而不是手动执行,如应用程序-强制停止
)。该如何实现?
我使用了:
android.os.Process.killProcess(android.os.Process.myPid());
system.exit(0);
它崩溃了。
我想在我的Android应用中强制停止一个应用程序,(而不是手动执行,如应用程序-强制停止
)。该如何实现?
我使用了:
android.os.Process.killProcess(android.os.Process.myPid());
system.exit(0);
它崩溃了。
android.os.Process.killProcess(android.os.Process.myPid());
这段代码是正确且最佳的。如果需要更多信息,请参考以下链接:如何关闭Android应用程序?和Process。
你也可以尝试这段代码:
Intent intent = new Intent(yourCurrentActivity.this, yourNextActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
android.os.Process.killProcess(android.os.Process.myPid());
?你想关闭你的应用程序还是第三方应用程序? - Sekarprivate void endapp() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
试试这个...
private void QuitApp() {
//getActivity().moveTaskToBack(true); //Move the task containing this activity to the back of the activity stack.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
System.exit(0);
}