I try to clear the event history stack when the user clicks on the logout button , even tried with IntentFlag Intent.FLAG_ACTIVITY_NO_HISTORY , but no luck. Take a look at my script mentioned below.
1) Login screen (end call)
2) The first screen (not causing the finish)
3) second screen (does not end)
4) Third screen (not causing the finish)
5) exit screen (it will open the login screen and end the job)
To achieve my goal m using the code below
Login screen
btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(MainActivity.this,FirstActivity.class); startActivity(intent); finish(); } });
login event
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (getIntent().getBooleanExtra("EXIT", false)) { this.finish(); }else{ this.finish(); } return true; } return super.onKeyDown(keyCode, event); }
First screen
btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(FirstActivity.this,SecondActivity.class); startActivity(intent); } });
Second screen
btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(SecondActivity.this,ThirdActivity.class); startActivity(intent); } });
Third screen
btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(ThirdActivity.this,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("EXIT", true); startActivity(intent); finish(); } });
The problem is that when I click the "Exit" button, it goes into the input activity, and when I click the "Back" button, it goes into the second activity.
why it doesnβt complete the action, and also why it goes to the second activity , if it supports the stack, then it should go to the first activity instead of the second one, when I push back from the login screen , I donβt know what kind of thing I am missing.
Update
Everything works fine if I delete finish() when I call the intent from the login screen, but I do not want to stay in the login window on the stack.
Your offer is available.