我有一个主要活动“仪表板”,其中包含一个包含主屏幕图标和退出按钮的操作栏,我从仪表板屏幕转到活动A - >活动B - >活动C.现在在C上,我点击操作栏仪表板图标,它在仪表板屏幕上显示给我。
现在我从仪表板屏幕转到活动E - >活动G->活动H.从H我按退出按钮,它进入C屏幕。当再次单击退出时,我将退出应用程序。
为什么需要按2次退出按钮退出应用程序。
在主屏幕图标上: -
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();
}
开启退出按钮: -
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();