当我的应用程序包含多个活动时如何退出应用程序?
How to Exit an application when my app consists of multiple activities?
当我在 android 中有多个活动时如何退出该应用程序?
我已经尝试了 finish()
和 System.exit(0)
,但其中 none 成功了。它所做的只是转到上一个 activity.
这是我的代码:
boolean insertionStatus = mydb.DataInsertion(email, password, username, fathername, contact, birthday, user_address);
if (insertionStatus)
{
alert.setTitle("Registration Status");
alert.setMessage("You are successfully registered!\nDo you want to login now?");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(intent);
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alert.create().show();
调用 finishAffinity(); 方法来完成之前的所有活动。
finishAffinity();
当我在 android 中有多个活动时如何退出该应用程序?
我已经尝试了 finish()
和 System.exit(0)
,但其中 none 成功了。它所做的只是转到上一个 activity.
这是我的代码:
boolean insertionStatus = mydb.DataInsertion(email, password, username, fathername, contact, birthday, user_address);
if (insertionStatus)
{
alert.setTitle("Registration Status");
alert.setMessage("You are successfully registered!\nDo you want to login now?");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(intent);
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alert.create().show();
调用 finishAffinity(); 方法来完成之前的所有活动。
finishAffinity();