现在的位置: 首页 > 综合 > 正文

Intent对象内置的Flag

2012年10月03日 ⁄ 综合 ⁄ 共 2302字 ⁄ 字号 评论关闭

Intent对象在Android开发中起着举足轻重的作用,其内置了丰富的常量,用于传递数据,下面本文将介绍跟Task有关的一些Flag参数,各参数的理解均来自Android API和本人在实际项目中的体验,如果有描述不当之处,还请各位不吝赐教。

 

FLAG_ACTIVITY_BROUGHT_TO_FRONT: 这个标志一般不是由程序代码设置的,如在launchMode中设置singleTask模式时系统帮你设定。

 

FLAG_ACTIVITY_CLEAR_TOP: 如果目标Activity已经运行于当前的Task中,则关闭Activity Stack中在此Activity上方的所有Activity,然后将此Intent传递到该Activity实例内。例如,假设一个Task的Activity Stack中包含这些Activity:A,B,C,D。如果D调用了startActivity(),并且Intent指向B,那么,C和D都将结束,然后B接收到这个Intent,因此,目前stack的状况是:A,B。

 

FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET: 如果设置,这将在Task的Activity Stack中设置一个还原点,当Task恢复时,需要清理Activity。例如下一次Task带着FLAG_ACTIVITY_RESET_TASK_IF_NEEDED标记进入前台时,这个Activity和它之上的都将关闭,以至于用户不能再返回到它们,但是可以回到之前的Activity。

FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS: 如果设置,新的Activity不会在最近启动的Activity的列表中保存。

 

FLAG_ACTIVITY_FORWARD_RESULT: 如果设置,并且这个Intent用于从一个存在的Activity启动一个新的Activity,那么,这个作为答复目标的Activity将会传到这个新的Activity中。这种方式下,新的Activity可以调用setResult(int),并且这个结果值将发送给那个作为答复目标的Activity。

 

FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY: 这个标志一般不由应用程序代码设置,如果这个Activity是从历史记录里启动的(常按HOME键),那么,系统会帮你设定。

 

FLAG_ACTIVITY_MULTIPLE_TASK: 不建议使用此标志,除非你自己实现了应用程序启动器。

 

FLAG_ACTIVITY_NEW_TASK: 将使Activity成为一个新Task的开始。

 

FLAG_ACTIVITY_NO_ANIMATION:  这个标志将阻止系统进入下一个Activity时应用Acitivity迁移动画。

 

FLAG_ACTIVITY_NO_HISTORY: 新的Activity将不再历史stack中保留。一旦离开,此Activity就关闭了。

 

FLAG_ACTIVITY_NO_USER_ACTION: 这个标志将在Activity暂停之前阻止从最前方的Activity回调的onUserLeaveHint()。

 

FLAG_ACTIVITY_PREVIOUS_IS_TOP: If set and this intent is being used to launch a new activity from an existing one, the current activity will not be counted as the top activity for deciding whether the new intent should be delivered to the top instead of
starting a new one. The previous activity will be used as the top, with the assumption being that the current activity will finish itself immediately.

 

FLAG_ACTIVITY_REORDER_TO_FRONT: 这个标志将引发已经运行的Activity移动到历史stack的顶端。

 

FLAG_ACTIVITY_RESET_TASK_IF_NEEDED: If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task. This will result in the application of any affinities needed
to have that task in the proper state (either moving activities to or from it), or simply resetting that task to its initial state if needed.

 

FLAG_ACTIVITY_SINGLE_TOP:  如果Activity位于Activity Stack的顶端,则不再创建一个新的实例。

 

  上面纷杂的Intent内置参数在简单的Android应用时,可以启到比较好的控制作用,但是一旦Android应用过于复杂,那么自定一个Activity List以管理Activity不失于一种更好更高效的管理方法。

 

转自:http://www.cnblogs.com/wisekingokok/archive/2011/08/21/2147897.html

抱歉!评论已关闭.