展会信息港展会大全

Android ApiDemos示例解析(13):App->Activity->Reorder Activities
来源:互联网   发布日期:2016-01-14 10:50:42   浏览:1919次  

导读:Reorder Activities 示例有四个相关的Activitives: ReorderOnLaunch, ReorderTwo,ReorderThree, ReorderFour。其中...

Reorder Activities 示例有四个相关的Activitives: ReorderOnLaunch, ReorderTwo,ReorderThree, ReorderFour。其中ReorderOnLaunch为主Activity,ReorderOnLaunch启动ReorderTwo ,ReorderTwo启动 ReorderThree,ReorderThree启动 ReorderFour。 这时在Activity的”back stack”有如下状态:

ReorderFour 想再启动ReorderTwo, 这时用两种实现方法,一是在 RecordFour之上再启动一个新的 ReorderTwo ,这是startActivity的缺省行为。这是因为在AndroidManifest.xml

<activity android:name=”.app.ReorderTwo” />

<activity android:name=”.app.ReorderThree” />

<activity android:name=”.app.ReorderFour” />

.app.RecordTwo没有定义任何这个Intent的Flag。 比如有 FLAG_ACTIVITY_NEW_TASK,FLAG_ACTIVITY_CLEAR_TOP,FLAG_ACTIVITY_SINGLE_TOP,在这些情况下 Android将根据不同Flag设置来决定启动RecordTwo的方法,具体在后面的例子会有介绍。

在Reorder Activities例子中,是将“Back Stack”中的ReorderTwo移到栈顶,方法是在启动Intent时设置Intent.FLAG_ACTIVITY_REORDER_TO_FRONT。如果设置了FLAG_ACTIVITY_REORDER_TO_FRONT表示将“Back Stack”中指定的Activity移动到栈顶。

[java]

Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

startActivity(intent);

Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

startActivity(intent);

此时栈如下图所示:

作者:mapdigit

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港