0

I have one main activity "Dashboard" with a action bar containing home screen icon and exit button , i go to activity A ->activity B ->activity C from dashboard screen . Now on C, i click on action bar dashboard icon which bring to me on Dashboard screen .

Now i go to activity E ->activity G->activity H from dashboard screen . From H i press exit button , it come to C screen . When again click on exit i go through me out of application.

Why there is need to press 2 times exit button for exit application .

On Home Screen Icon :-

    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 exit button :-

    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();
frozenhill
  • 124
  • 1
  • 9
Sushant Bhatnagar
  • 3,684
  • 10
  • 31
  • 42
  • This would be a good place to start - http://stackoverflow.com/questions/5001882/how-to-clear-specific-activity-from-the-stack-history As would this http://stackoverflow.com/questions/6211444/finishing-all-activities-started-before-the-activity – jcw Nov 11 '12 at 10:10

1 Answers1

2

If I understood well, you should solve this thanks to the use of finish().

Taking a look to this post might help.

Community
  • 1
  • 1
kosklain
  • 399
  • 3
  • 17