The problem: Lets say I have 3 activities: MainMenu, LevelSelection and Game. I have a button that run an intent in MainMenu to redirect the player to LevelSelection. In LevelSelection is another button that redirect the player to Game. When the activity Game ends it run an intent to redirect the player to the MainMenu activity. However, when tested, the redirection is done to LevelSelection instead of MainMenu.
MainMenu => LevelSelection code
this.finish();
Intent intent = new Intent(this, LevelSelection.class);
this.startActivity(intent);
LevelSelection => Game code
this.finish();
Intent intent = new Intent(this, Game.class);
this.startActivity(intent);
Game => MeainMenu code
this.finish();
Intent intent = new Intent(this, MainMenu.class);
this.startActivity(intent);
Thanks in advance.
In the manifest, I would set
No historytotruefor all your activities. This will prevent the user from going back to a previous activity when the current one closes (or when the user presses “back”). This might be helpful since you’re trying to have strict control over what activity the user goes to.I would also remove
this.finish(). I think you’re closing the activity before the intent is started. Hence why it goes back to the previous activity instead of the new one.Another solution would be to set ‘No history’ to ‘true’ only for
LevelSelection. Then, you can simply close the ‘Game’ activity, and it should go back toMainMenu.