gpt4 book ai didi

android - "Up"的正确处理方式 Navigation according to guidelines

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:50 26 4
gpt4 key购买 nike

我完全同意下面的导航

enter image description here

假设 Book 详细信息是在 BookDetailActivity 的不同实例中创建的。

book2 详情中压上前的栈是:

  • BookDetailActivity(第 2 本书 - 你在这里)
  • BookDetailActivity(第 1 本书)
  • AllBooksActivity

如果我按照 guidelines我将使用:

     Intent parentActivityIntent = new Intent(this, AllBooksActivity.class);
parentActivityIntent.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(parentActivityIntent);
finish();

但是这段代码的大问题是 BookDetailActivity(第 1 本书)仍然存在!

在“向上”后按返回按钮将显示第 1 本书的详细信息。

如何杀死原始 AllBooksActivity 和我按下的 Activity 之间的所有 BookDetailActivity

最佳答案

related guidelines article注意以下几点:

Implementation Note: As a best practice, when implementing either Home or Up, make sure to clear the back stack of any descendent screens. For Home, the only remaining screen on the back stack should be the home screen. For Up navigation, the current screen should be removed from the back stack, unless Back navigates across screen hierarchies. You can use the FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK intent flags together to achieve this.

既然你这样做了,BookDetailActivity1 应该被 FLAG_ACTIVITY_CLEAR_TOP 关闭.如果它可以在按下返回时处于 Activity 状态并显示,唯一的方法是它是否在 AllBooksActivity 之前启动。

至于不需要FLAG_ACTIVITY_NEW_TASK (由 android 开发者 的回答建议):

When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in.

...所以如果您的 Activity 存在,它不会启动新任务。

关于android - "Up"的正确处理方式 Navigation according to guidelines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14040620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com