gpt4 book ai didi

android - 为什么要使用启动 Activity ?

转载 作者:可可西里 更新时间:2023-11-01 19:03:10 27 4
gpt4 key购买 nike

我一直在查看 API 文档,并注意到从 API 级别 16 开始 Context类包括以下方法:

public abstract void startActivities (Intent[] intents)

我一直在谷歌搜索,试图通过在应用程序代码、问题或文章中使用它的示例来满足我的好奇心,但到目前为止我还没有找到任何东西。如果有人已经问过类似的问题,请告诉我。

无论如何,我很好奇什么时候应该/可以在应用程序代码中使用它,这样做有什么好处(如果有的话)?我个人从未见过使用过这种方法,而且我无法理解它的实用性。任何反馈将不胜感激。

最佳答案

它很少在应用程序代码中使用。我本来想说永远不会,但我不是那个肯定的;)

但是,它可以用于在启动新任务时创建一个合成后退堆栈。您想要一个现成的返回堆栈,以便返回键在此任务中“分层”导航。

奇怪的是,documentation of ContextCompat 中对此有更好的解释而不是 Context 本身。

Start a set of activities as a synthesized task stack, if able.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

startActivities provides a mechanism for constructing a synthetic task stack of multiple activities. If the underlying API is not available on the system this method will return false.

关于android - 为什么要使用启动 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24295906/

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