I have been spending lots of hours figuring the reason why top of the stack is not cleared yet.
Well I tried the following:
Intent intent = new Intent(ActionBarActivity.this, MainActivity.class);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
And it turned me to the MainActivity
. Then when I try to press back button, the program does not exit, but instead it turns me to the first page of ActionBarActivity
.
Let me be more specific:
In MainActivity
I call ActionBarActivity
. In the ActionBarActivity
I have a search bar and I enter a query there and just print the value of the query.
If you think how it will work is a below:
MainActivity
-> ActionBarActivity1
-> ActionBarActivity2
-> ActionBarActivity3
-> ..
In that ActionBarActivity
I have also an option which brings me back to the MainActivity
.
So as I said when I run application with the way above, it will bring me to the MainActivity
.
Nice so far, but when I press the back button I expect it to exit, but instead it goes to ActionBarActivity1
. I doubt the stack is not properly erased.
What should I do in this case. Thanks