I created an application with several pages and the transition from one to another is an important stream. I donβt want the user to be able to click the "Back" button and avoid the activity without prior warning, and then finally delete the entire stack trace so that when the activity is restarted, it starts again.
At the moment, I used something similar to the function below:
@Override public void onBackPressed() { this.finish(); Intent int1= new Intent(this, Home.class); int1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(int1); super.onBackPressed(); }
But sometimes, when after exiting the application when it starts, it restarts from some random page or from the one where I exit the application (basically not on the main screen, where it should start from)
I cannot think of an easier way to exit the application, except to clear all previous activity flags, as described in the code. Any help on the above is appreciated!
EDIT:
At any time during the flow of my activity, if the user clicks the back button, I want the control to be returned to the main page (clearing all previous stacks of the activity stack). Thus, if someone remakes the application, he will start normally from the main page.
source share