我有一个主要活动“仪表板”,其中包含一个包含主屏幕图标和退出按钮的操作栏,我从仪表板屏幕转到活动 A -> 活动 B -> 活动 C。现在在 C 上,我单击操作栏仪表板图标,它会在仪表板屏幕上显示给我。
现在我从仪表板屏幕转到活动 E -> 活动 G-> 活动 H。从 H i 按退出按钮,它来到 C 屏幕。当再次单击退出时,我通过我退出应用程序。
为什么退出应用程序需要按两次退出按钮。
在主屏幕图标上:-
public void onClickHome(View view){
final Intent intent = new Intent(getBaseContext(), Dashboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
getBaseContext().startActivity(intent);
//goDashboard();
}
ON 退出按钮:-
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getString(R.string.logoutDialogTitle));
alert.setMessage(getString(R.string.logoutDialogMessage));
final OnlineBookApp app = (OnlineBookApp) getApplicationContext();
alert.setPositiveButton(getString(R.string.logoutDialogCancel), new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton(getString(R.string.logoutDialogOk),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//finish();
//stopService(new Intent(getBaseContext(), DatabaseSyncService.class));
//
// moveTaskToBack(true);
//// stopService(new Intent(getBaseContext(),
DatabaseSyncService.class));
// System.runFinalizersOnExit(true);
// android.os.Process.killProcess(android.os.Process.myPid());
//moveTaskToBack(true);
// finish();
// app.SetIsExit(true);
Intent intent = new Intent(getApplicationContext(), Dashboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
});
alert.setNeutralButton(getString(R.string.logoutDialogLogout), new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//finish();
//stopService(new Intent(getBaseContext(),
DatabaseSyncService.class));
//finish();
//app.SetIsExit(true);
//stopService(new Intent(getBaseContext(),
DatabaseSyncService.class));
app.logout();
Intent intent = new Intent(getApplicationContext(),
Dashboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
});
alert.show();