我怎样才能让一个 Activity 返回到另一个 Activity 而不是那个叫做 startactivity 的 Activity ?
我有一款游戏,用户可以从现有游戏列表中选择玩游戏或选择开始新游戏。开始新游戏时,如果游戏列表变为 Activity 状态而不是返回 Activity 状态以创建新游戏,我希望在用户完成轮到他时这样做。
在各种 Activity 中,
目前做什么:
selectGames
playGame --- return to selectGames
or
createNewGame --- playGame --- return to createNewGame --- return to selectGames
我希望它:
selectGames
playGame --- return to selectGames
or
createNewGame --- playGame --- return to selectGames
有没有办法插入一个 Intent ,或者从 createNewGame 开始一个 Activity 时 用户可以完成或暂停游戏并返回选择游戏吗?如果 Intent 在堆栈上,我想从 Intent 堆栈中删除 createNewGame(这有意义吗?)
最佳答案
注意:每次调用一个 Activity 时,您都会将父 Activity 放在已暂停 Activity 的堆栈中:
选择游戏 -> 创建新游戏 -> 玩游戏
但是您可以在需要时终止 Activity,它将从堆栈中删除。
当您从 createNewGame
调用 playGame
时,您可以使用此代码:
startActivity(playGame); //Put playGame in the top of stack
finish(); //Remove createNewGame (current Activity) from the stack
新订单是:
选择游戏 -> 玩游戏
然后您将从堆栈中删除 createNewGame
并远离从 playGame
返回到 createNewGame
调用方。 selectGames
在这种情况下。
关于android - 启动 Activity 并返回不同的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13505557/