android – 为什么要使用开始活动?

前端之家收集整理的这篇文章主要介绍了android – 为什么要使用开始活动?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在浏览API文档,并注意到从API级别16开始,Context包括以下方法

public abstract void startActivities(Intent [] intents)

我一直在Googling试图通过在应用程序代码,问题或文章中使用的例子来展现我的好奇心,但是至今还没有遇到任何问题.如果有人问过类似的问题,请通知我.

无论如何,我很好奇应该在应用程序代码中使用什么,什么(如果有的话)这样做的好处是什么?我个人从未看过这种方法,我无法掌握它的实用性.任何反馈将不胜感激.

解决方法

它很少在应用程序代码中使用.我不会说,但我不太确定;)

但是,当启动新的任务时,它可以用于创建一个合成的后备栈.您想要有一个现成的后备堆栈,以便后面的密钥在此任务内“分层”导航.

奇怪的是,在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相关文章