在 android 中单击默认返回后如何退出应用程序?
How to exit from an application after click default back in android?
我想在单击返回后退出应用程序 android phone.Actually 我不知道那个返回选项的确切词。Screen shot of back option
我真的知道单击后退出应用程序的方法 button.So 我该如何编写代码?我可以这样做吗?
如果您已经知道逻辑并将其附加到按钮,则可以覆盖
@Override
public void onBackPressed() {
}
在你的 activity 中,并把相同的逻辑放在那里
引用自this问题:
Android's design does not favor exiting an application by choice, but
rather manages it by the OS. You can bring up the Home application by
its corresponding Intent:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
请注意,他不会终止您的应用程序进程,而是将您的 activity 置于后台。
至于何时触发此代码,您应该为您当前的 activity.
重写 onBackPressed()
方法
只需通过此代码(如果您当前的后台堆栈中只有一个 activity 重新挖矿。)由 feresr
更正
@Override
public void onBackPressed() {
// your code, what to do under back arrow button.
finish(); // to finish app or activity
}
在您的 activity 中,您可以覆盖方法 onBackPressed:
@Override
public void onBackPressed() {
finish();
}
如果你有一堆活动
还有更好的方法:
@Override
public void onBackPressed() {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
我想在单击返回后退出应用程序 android phone.Actually 我不知道那个返回选项的确切词。Screen shot of back option
我真的知道单击后退出应用程序的方法 button.So 我该如何编写代码?我可以这样做吗?
如果您已经知道逻辑并将其附加到按钮,则可以覆盖
@Override
public void onBackPressed() {
}
在你的 activity 中,并把相同的逻辑放在那里
引用自this问题:
Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
请注意,他不会终止您的应用程序进程,而是将您的 activity 置于后台。 至于何时触发此代码,您应该为您当前的 activity.
重写onBackPressed()
方法
只需通过此代码(如果您当前的后台堆栈中只有一个 activity 重新挖矿。)由 feresr
更正@Override
public void onBackPressed() {
// your code, what to do under back arrow button.
finish(); // to finish app or activity
}
在您的 activity 中,您可以覆盖方法 onBackPressed:
@Override
public void onBackPressed() {
finish();
}
如果你有一堆活动 还有更好的方法:
@Override
public void onBackPressed() {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}