android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">allowTaskReparenting</span><wbr style="line-height:25px"><br style="line-height:25px"> 用来标记Activity能否从启动的Task移动到有着affinity的Task(当这个Task进入到前台时)——“true”,表示能移动,“false”,表示它必须呆在启动时呆在的那个Task里。<br style="line-height:25px"> 如果这个特性没有被设定,设定到<application>元素上的allowTaskReparenting特性的值会应用到Activity上。默认值为“false”。<br style="line-height:25px"> 一般来说,当Activity启动后,它就与启动它的Task关联,并且在那里耗尽它的整个生命周期。当当前的Task不再显示时,你可以使用这个特性来强制Activity移动到有着affinity的Task中。典型用法是:把一个应用程序的Activity移到另一个应用程序的主Task中。<br style="line-height:25px"> 例如,如果e-mail中包含一个web页的链接,点击它就会启动一个Activity来显示这个页面。这个Activity是由Browser应用程序定义的,但是,现在它作为e-mailTask的一部分。如果它重新宿主到BrowserTask里,当Browser下一次进入到前台时,它就能被看见,并且,当e-mailTask再次进入前台时,就看不到它了。<br style="line-height:25px"> Actvity的affinity是由taskAffinity特性定义的。Task的affinity是通过读取根Activity的affinity来决定的。因此,根据定义,根Activity总是位于相同affinity的Task里。由于启动模式为“singleTask”和“singleInstance”的Activity只能位于Task的底部,因此,重新宿主只能限于“standard”和“singleTop”模式。<br style="line-height:25px"> android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">alwaysRetainTaskState</span><wbr style="line-height:25px"><br style="line-height:25px"> 用来标记Activity所在的Task的状态是否总是由系统来保持——“true”,表示总是;“false”,表示在某种情形下允许系统恢复Task到它的初始化状态。默认值是“false”。这个特性只针对Task的根Activity有意义;对其它Activity来说,忽略之。<br style="line-height:25px"> 一般来说,特定的情形如当用户从主画面重新选择这个Task时,系统会对这个Task进行清理(从stack中删除位于根Activity之上的所有Activivity)。典型的情况,当用户有一段时间没有访问这个Task时也会这么做,例如30分钟。<br style="line-height:25px"> 然而,当这个特性设为“true”时,用户总是能回到这个Task的最新状态,无论他们是如何启动的。这非常有用,例如,像Browser应用程序,这里有很多的状态(例如多个打开的Tab),用户不想丢失这些状态。<br style="line-height:25px"> android<span style="color:#ff00ff; line-height:25px">:clearTaskOnLaunch</span><br style="line-height:25px"> 用来标记是否从Task中清除所有的Activity,除了根Activity外(每当从主画面重新启动时)——“true”,表示总是清除至它的根Activity,“false”表示不。默认值是“false”。这个特性只对启动一个新的Task的Activity(根Activity)有意义;对Task中其它的Activity忽略。<br style="line-height:25px"> 当这个值为“true”,每次用户重新启动这个Task时,都会进入到它的根Activity中,不管这个Task最后在做些什么,也不管用户是使用BACK还是HOME离开的。当这个值为“false”时,可能会在一些情形下(参考alwaysRetainTaskState特性)清除Task的Activity,但不总是。<br style="line-height:25px"> 假设,某人从主画面启动了ActivityP,并从那里迁移至ActivityQ。接下来用户按下HOME,然后返回ActivityP。一般,用户可能见到的是ActivityQ,因为它是P的Task中最后工作的内容。然而,如果P设定这个特性为“true”,当用户按下HOME并使这个Task再次进入前台时,其上的所有的Activity(在这里是Q)都将被清除。因此,当返回到这个Task时,用户只能看到P。<br style="line-height:25px"> 如果这个特性和allowTaskReparenting都设定为“true”,那些能重新宿主的Activity会移动到共享affinity的Task中;剩下的Activity都将被抛弃,如上所述。<br style="line-height:25px"> android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">finishOnTaskLaunch</span><wbr style="line-height:25px"><br style="line-height:25px"> 用来标记当用户再次启动它的Task(在主画面选择这个Task)时已经存在的Activity实例是否要关闭(结束)——“true”,表示应该关闭,“false”表示不关闭。默认值是“false”。<br style="line-height:25px"> 如果这个特性和allowTaskReparenting都设定为“true”,这个特性胜出。Activity的affinity忽略。这个Activity不会重新宿主,但是会销毁。<br style="line-height:25px"> android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">launchMode</span><wbr style="line-height:25px"><br style="line-height:25px"> 用于指示Activity如何启动。这里有四种模式,与Intent对象中的ActivityFlags(FLAG_ACTIVITY_*变量)共同作用,来决定Activity如何启动来处理Intent。<br style="line-height:25px"> 它们是<span style="color:#0000ff; line-height:25px">"standard","singleTop","singleTask","singleInstance"</span> 。 默认模式是“standard”。 <div style="line-height:25px">这些模式可以分成两大组别,“<span style="color:#99cc00; line-height:25px">standard”和</span>“<span style="color:#808000; line-height:25px">singleTop</span>”一组,“<span style="color:#339966; line-height:25px">singleTask</span>”和“<span style="color:#008000; line-height:25px">singleInstance</span>”一组。</div> <div style="line-height:25px">“<span style="color:#ff00ff; line-height:25px">standard</span>”和“<span style="color:#ff00ff; line-height:25px">singleTop</span>”模式的Activity可以实例化很多次。这些实例可以属于任何Task并且可以位于Activitystack的任何位置。<br style="line-height:25px"><span style="color:#000080; line-height:25px">典型的情况是,它们会进入调用</span><span style="color:#0000ff; line-height:25px">startActivity()</span><span style="color:#000080; line-height:25px">的Task(除非Intent对象包含FLAG_ACTIVITY_NEW_TASK标志,在这种情况下会选择一个不同的Task——参考taskAffinity特性)。</span> </div> <div style="line-height:25px"> <span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"> <span style="color:#000080; line-height:25px"></span></span><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="color:#000080; line-height:25px">对于“</span><span style="color:#ff00ff; line-height:25px">standard</span><span style="color:#000080; line-height:25px">”的Activity来说,都是创建一个新的实例来响应新的Intent。每个实例处理一个Intent。</span></span><span style="color:#000080; line-height:22px">每次有一个新的启动“</span><span style="color:#ff00ff; line-height:22px">standard</span><span style="color:#000080; line-height:22px">”Activity的Intent,就会创建一个新的实例来响应这个Intent。每个实例处理一个Intent。</span> </div> <div style="line-height:25px"> <span style="color:#000080; line-height:22px"> 对于“</span><span style="color:#ff00ff; line-height:22px">singleTop</span><span style="color:#000080; line-height:22px">”的Activity来说,却并不总是</span><span style="color:#000080; line-height:22px"><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53">创建一个新的实例来响应新的Intent</span>。</span><span style="color:#000080; line-height:22px"> 在目标Task已经有一个存在的实例并且位于stack的顶部的情况下,这个实例会接收到这个新的Intent(调用onNewIntent());而不用创建新的实例</span>。</div> <div style="line-height:25px"> <span style="color:#000080; line-height:25px">在其他情况下——例如,如果存在的“singleTop”的Activity实例在目标Task中,但不是在stack的顶部,或者它在一个stack的顶部,但不是在目标Task中——新的实例都会被创建并压入stack中。</span><br style="line-height:25px"><span style="font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><span style="line-height:25px">例如,假设一个Task的Activitystack中包含根ActivityA和其它ActivityB,C,D,并且D位于顶端,因此,stack是A-B-C-D。有一个Intent来了,它要启动D类型的Activity。如果D是默认的“standard”启动模式,那么一个新的实例将被启动并且stack变成A-B-C-D-D。</span></span><br style="line-height:25px"><span style="font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><span style="line-height:25px">然而,如果D的启动模式“singleTop”,已经存在的实例将去处理新来的Intent(因为它正好处在stack的顶端),并且stack依旧是A-B-C-D。</span></span><br style="line-height:25px"><span style="font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><span style="line-height:25px">换句话说,如果来临的Intent是冲着B类型的,那么,B类型的实例将被创建启动而不管B的模式是“standard”或“singleTop”(因为B不处在stack的顶端),因此,stack将会是A-B-C-D-B。</span></span><br style="line-height:25px"> 相反的,“<span style="color:#ff00ff; line-height:25px">singleTask</span>”和<span style="color:#ff00ff; line-height:25px">“singleInstance</span>”模式的Activity<span style="color:#000080; line-height:25px">只能有一个实例,也只能存在于一个Task中</span><wbr style="line-height:25px">。对于“<span style="color:#339966; line-height:25px">singleInstance</span>”的Activity总是位于Activitystack的底部。对于“<span style="color:#008000; line-height:25px">singleTask</span>”的Activity,不一定位于Activitystack的底部。</wbr> </div> <div style="line-height:25px"> “<span style="color:#ff00ff; line-height:25px"><span style="line-height:22px">singleTask</span><span style="line-height:22px">”</span></span><span style="color:#000080; line-height:22px">Activity允许其它Activity成为它的Task的部分。当启动时,如果没有找到和它android:</span><span style="line-height:22px"><span style="color:#339966; line-height:22px"><wbr style="line-height:22px">taskAffinity</wbr></span></span><span style="line-height:22px; color:rgb(0,0,128)">一样的task</span><span style="line-height:22px; color:rgb(0,0,128)">,系统就新建一个Task来存放它,这时它当然也就位于</span><span style="color:#000080; line-height:22px">stack的底部。如果找到了,则看该Task中是否已经有该Activity的实例,如果没有,就创建它,并把它压人stack,放在stack的顶部;如果有,则由该</span><span style="color:#000080; line-height:22px"><span style="line-height:25px; color:rgb(0,0,0); font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="color:#003366; line-height:25px">Activity去处理这个Intent,Intent对象将传到该Activity的</span><span style="color:#ff6600; line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">onNewIntent</wbr></span><wbr style="line-height:25px">()</wbr></span><span style="color:#003366; line-height:25px">的方法中,这时如果</span></span><span style="line-height:25px; color:rgb(0,0,0); font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="color:#003366; line-height:25px">上方有其他的Activity的话,所有Activity会被清除掉,当然也Destroy</span></span>。另外,其它Activity(必须是“standard”和“singleTop”Activity)可以启动加入到“</span><span style="color:#339966; line-height:22px">singleTask</span><span style="color:#000080; line-height:22px">”Activity所在的Task中。</span><br style="line-height:25px"><span style="color:#000080; line-height:25px">“</span><span style="color:#ff00ff; line-height:25px">singleInstance</span><span style="color:#000080; line-height:25px">”Activity,换句话说,不允许其它Activity成为它的Task的部分。它是Task中的唯一Activity。如果它启动其它的Activity,这个Activity会被放置到另一个task中——好像Intent中包含了</span><span style="color:#0000ff; line-height:25px">FLAG_ACTIVITY_NEW_TASK</span><span style="color:#000080; line-height:25px">标志。</span> </div> <div style="line-height:25px"> <span style="color:#000080; line-height:25px"><span style="line-height:25px; color:rgb(0,0,0)"><span style="color:#000080; line-height:22px">对于</span></span></span><span style="color:#000080; line-height:22px">“</span><span style="color:#008000; line-height:22px">singleInstance</span><span style="color:#000080; line-height:22px">”Activity,如果启动时发现有该Activity的实例,</span><span style="color:#000080; line-height:22px">则由该</span><span style="color:#000080; line-height:22px"><span style="line-height:25px; color:rgb(0,0,0); font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="color:#003366; line-height:25px">Activity去处理这个Intent,Intent对象将传到该Activity的</span><span style="color:#ff6600; line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">onNewIntent</wbr></span><wbr style="line-height:25px">()</wbr></span><span style="color:#003366; line-height:25px">的方法中,</span></span></span><span style="line-height:25px; color:rgb(0,0,128)">如果没有,就创建一个task,并创建一个Activity实例来放入其中,让它来处理Intent.</span> </div> <div style="line-height:25px">android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">noHistory</span><wbr style="line-height:25px"><br style="line-height:25px"> 用于标记当用户从Activity上离开并且它在屏幕上不再可见时Activity是否从Activitystack中清除并结束(调用finish()方法)——“true”,表示它应该关闭,“false”,表示不需要。默认值是“false”。<br style="line-height:25px"> “true”值意味着Activity不会留下历史痕迹。因为它不会在Activitystack的Task中保留,因此,用户不能返回它。<br style="line-height:25px"> 注意1:该Activity会在用户离开时,或在任务管理器再次选择它时销毁。<br style="line-height:25px"> android:<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">taskAffinity</span><wbr style="line-height:25px"><br style="line-height:25px"> Activity为Task拥有的一个affinity。拥有相同的affinity的Activity理论上属于相同的Task(在用户的角度是相同的“应用程序”)。Task的affinity是由它的根Activity决定的。<br style="line-height:25px"> affinity决定两件事情——<span style="color:#000080; line-height:25px">Activity重新宿主的Task(参考allowTaskReparenting特性)和使用FLAG_ACTIVITY_NEW_TASK标志启动的Activity宿主的Task。</span><br style="line-height:25px"> 默认情况,一个应用程序中的所有Activity都拥有相同的affinity。也可以设定这个特性来重组它们,甚至可以把不同应用程序中定义的Activity放置到相同的Task中。<br style="line-height:25px"> 为了明确Activity不宿主特定的Task,设定该特性为空的字符串。<br style="line-height:25px"> 如果这个特性没有设置,Activity将从应用程序的设定那里继承下来(参考<application>元素的<span style="color:#0000ff; line-height:25px">taskAffinity</span>特性)。应用程序默认的affinity的名字是<manifest>元素中设定的<span style="color:#0000ff; line-height:25px">package</span>名。</wbr></wbr></wbr></wbr> </div> <div style="line-height:25px"> <span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="line-height:25px">注意</span>:对singleInstance的Activity的affinity最好不要和别的task的affinity相冲突。</span><br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_BROUGHT_TO_FRONT</span><wbr style="line-height:25px"><br style="line-height:25px"> 这个标志一般不是由程序代码设置的,如在launchMode中设置singleTask模式时系统帮你设定。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_CLEAR_TOP</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#003366; line-height:25px">如果设置,并且这个Activity已经在当前的Task中运行,因此,不再是重新启动一个这个Activity的实例,而是在这个Activity上方的所有Activity都将关闭,然后这个Intent会作为一个新的Intent投递到老的Activity(现在位于顶端)中。<br style="line-height:25px"> 例如,假设一个Task中包含这些Activity:A,B,C,D。如果D调用了startActivity(),并且包含一个指向ActivityB的Intent,那么,C和D都将结束,然后B接收到这个Intent,因此,目前stack的状况是:A,B。<br style="line-height:25px"> 上例中正在运行的ActivityB既可以在</span><span style="color:#ff6600; line-height:25px">onNewIntent()</span><span style="color:#003366; line-height:25px">中接收到这个新的Intent,也可以把自己关闭然后重新启动来接收这个Intent</span>。如果它的启动模式声明为“<span style="color:#0000ff; line-height:25px">standard</span>”(默认值),<br style="line-height:25px"> 并且你没有在这个Intent中设置<span style="color:#0000ff; line-height:25px">FLAG_ACTIVITY_SINGLE_TOP</span>标志,那么它将关闭然后重新创建;对于其它的启动模式,或者在这个Intent中设置<span style="color:#0000ff; line-height:25px">FLAG_ACTIVITY_SINGLE_TOP</span>标志,都将把这个Intent投递到当前这个实例的<span style="color:#ff6600; line-height:25px">onNewIntent()</span>中。<br style="line-height:25px"> 这个启动模式还可以与<span style="color:#0000ff; line-height:25px">FLAG_ACTIVITY_NEW_TASK</span>结合起来使用:用于启动一个Task中的根Activity,它会把那个Task中任何运行的实例带入前台,然后清除它直到根Activity。这非常有用,例如,当从NotificationManager处启动一个Activity。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果设置,这将在Task的Activitystack中设置一个还原点,当Task恢复时,需要清理Activity。也就是说,下一次Task带着<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_RESET_TASK_IF_NEEDED</span><wbr style="line-height:25px">标记进入前台时(典型的操作是用户在主画面重启它),<br style="line-height:25px"> 这个Activity和它之上的都将关闭,以至于用户不能再返回到它们,但是可以回到之前的Activity。<br style="line-height:25px"> 这在你的程序有分割点的时候很有用。例如,一个e-mail应用程序可能有一个操作是查看一个附件,需要启动图片浏览Activity来显示。这个Activity应该作为e-mail应用程序Task的一部分,因为这是用户在这个Task中触发的操作。<br style="line-height:25px"> 然而,当用户离开这个Task,然后从主画面选择e-mailapp,我们可能希望回到查看的会话中,但不是查看图片附件,因为这让人困惑。<br style="line-height:25px"> 通过在启动图片浏览时设定这个标志,浏览及其它启动的Activity在下次用户返回到mail程序时都将全部清除。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果设置,新的Activity不会在最近启动的Activity的列表中保存。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_FORWARD_RESULT</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果设置,并且这个Intent用于从一个存在的Activity启动一个新的Activity,新的Activity中对前一个Activity的回复将没传送到该Activity。<br style="line-height:25px"> 这种方式下,新的Activity可以调用setResult(int)或setResult(intresultCode,Intentdata),并且这个结果值将发送给那个作为答复目标的Activity。<br style="line-height:25px"> 注意:感觉它和startActivityForResult的功能差不多,但是还是有疑惑。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY</span><wbr style="line-height:25px"><br style="line-height:25px"> 这个标志一般不由应用程序代码设置,如果这个Activity是从历史记录里启动的(常按HOME键),那么,系统会帮你设定。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_MULTIPLE_TASK</span><wbr style="line-height:25px"><br style="line-height:25px"> 不要使用这个标志,除非你自己实现了应用程序启动器。与FLAG_ACTIVITY_NEW_TASK结合起来使用,可以禁用把已存的Task送入前台的行为。当设置时,新的Task总是会启动来处理Intent,而不管这是是否已经有一个Task可以处理相同的事情。<br style="line-height:25px"> 由于默认的系统不包含图形Task管理功能,因此,你不应该使用这个标志,除非你提供给用户一种方式可以返回到已经启动的Task。<br style="line-height:25px"> 如果FLAG_ACTIVITY_NEW_TASK标志没有设置,这个标志被忽略。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_NEW_TASK</span><wbr style="line-height:25px"><br style="line-height:25px"> 一个Activity一般通过调用startActivity()启动并加入到Task中。它同调用者一样,进入同一个Task。<br style="line-height:25px"> 然而,如果传递给startActivity()的Intent对象中包含FLAG_ACTIVITY_NEW_TASK时,系统会搜索一个新的Task来容纳新的Activity。<br style="line-height:25px"> 通常,如标志的名字所示,是一个新的Task。然而,并不是必须是。如果已经存在一个Task与新Activity的affinity相同,这个Activity就会加入到那个Task中。如果不是,启动一个新的Task。<br style="line-height:25px"> 如果启动它的acitve和新Activity的affinity相同,那么新Activity的会进入启动它的acitve所在的Task.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#993300; line-height:25px">FLAG_ACTIVITY_NO_ANIMATION</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果在Intent中设置,并传递给Context.startActivity()的话,这个标志将阻止系统进入下一个Activity时应用Acitivity迁移动画。<br style="line-height:25px"> 这并不意味着动画将永不运行——如果另一个Activity在启动显示之前,没有指定这个标志,那么,动画将被应用。<br style="line-height:25px"> 这个标志可以很好的用于执行一连串的操作,而动画被看作是更高一级的事件的驱动。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_NO_HISTORY</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果设置,新的Activity将不再历史stack中保留。用户一离开它,这个Activity就关闭了。这也可以通过设置noHistory特性来达到同样目的。<br style="line-height:25px"> 注意1:该Activity会在用户离开时,有时要直到离开后再回来时才销毁。但是对于noHistory特性,在任务管理器再次选择它时也会被销毁。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_NO_USER_ACTION</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果设置,作为新启动的Activity进入前台时,这个标志将阻止现在在最前方的Activity因为我们新的Activity要启动而暂停时回调onUserLeaveHint()。<br style="line-height:25px"> 一个Activity可以依赖这个回调(onUserLeaveHint())指明是显式的用户动作引起的Activity移出后台。<br style="line-height:25px"> 这个回调在Activity的生命周期中标记一个合适的点,并关闭一些Notification。<br style="line-height:25px"> 如果一个Activity是通过非用户驱动的事件启动,如来电或闹钟,启动的,这个标志也应该传递给Context.startActivity,<br style="line-height:25px"> 这样保证暂停的Activity不认为用户已经知晓其Notification。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意1</wbr></span><wbr style="line-height:25px">:如果一个Activity通过非用户驱动的事件,如来电或闹钟,启动的,这个标志也应该传递给Context.startActivity。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意2</wbr></span><wbr style="line-height:25px">:关于onUserLeaveHint的内容请参照附1.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#993300; line-height:25px">FLAG_ACTIVITY_PREVIOUS_IS_TOP</span><wbr style="line-height:25px"><br style="line-height:25px"> Ifsetandthisintentisbeingusedtolaunchanewactivityfromanexistingone,<br style="line-height:25px"> thecurrentactivitywillnotbecountedasthetopactivityfordecidingwhetherthenewintentshouldbedeliveredtothetopinsteadofstartinganewone.<br style="line-height:25px"> Thepreviousactivitywillbeusedasthetop,withtheassumptionbeingthatthecurrentactivitywillfinishitselfimmediately.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#993300; line-height:25px">FLAG_ACTIVITY_REORDER_TO_FRONT</span><wbr style="line-height:25px"><br style="line-height:25px"> 如果在Intent中设置,并传递给Context.startActivity(),这个标志将引发已经运行的Activity移动到历史stack的顶端。<br style="line-height:25px"> 例如,假设一个Task由四个Activity组成:A,B,C,D。如果D调用startActivity()来启动ActivityB,那么,B会移动到历史stack的顶端,现在的次序变成A,C,D,B。<br style="line-height:25px"> 如果FLAG_ACTIVITY_CLEAR_TOP标志也设置的话,那么这个标志将被忽略。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#993300; line-height:25px">FLAG_ACTIVITY_RESET_TASK_IF_NEEDED</span><wbr style="line-height:25px"><br style="line-height:25px"> Ifset,andthisactivityiseitherbeingstartedinanewtaskorbringingtothetopanexistingtask,<br style="line-height:25px"> thenitwillbelaunchedasthefrontdoorofthetask.Thiswillresultintheapplicationofanyaffinitiesneededtohavethattaskintheproperstate(eithermovingactivitiestoorfromit),<br style="line-height:25px"> orsimplyresettingthattasktoitsinitialstateifneeded.<br style="line-height:25px"> 注意1:不太明白<br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">FLAG_ACTIVITY_SINGLE_TOP</span><br style="line-height:25px"> 如果设置,当这个Activity位于历史stack的顶端运行时,不再启动一个新的。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">附1</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> protectedvoid<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">onUserLeaveHint<wbr style="line-height:25px">()</wbr></span><br style="line-height:25px"> Since:APILevel3<br style="line-height:25px"> Calledaspartoftheactivitylifecyclewhenanactivityisabouttogointothebackgroundastheresultofuserchoice.<br style="line-height:25px"> Forexample,whentheuserpressestheHomekey,onUserLeaveHint()willbecalled,butwhenanincomingphonecallcausesthein-callActivitytobeautomaticallybroughttotheforeground,<br style="line-height:25px"> onUserLeaveHint()willnotbecalledontheactivitybeinginterrupted.<br style="line-height:25px"> Incaseswhenitisinvoked,thismethodiscalledrightbeforetheactivity'sonPause()callback.<br style="line-height:25px"> ThiscallbackandonUserInteraction()areintendedtohelpactivitiesmanagestatusbarnotificationsintelligently;<br style="line-height:25px"> specifically,forhelpingactivitiesdeterminethepropertimetocancelanotfication.<br style="line-height:25px"> 作为activity周期的一部分,它在activity因为用户要跳转到别的activity而要退到background时使用。<br style="line-height:25px"> 比如,在用户按下Home键(用户的choice),它将被调用。比如有电话进来(不属于用户的choice),它就不会被调用。<br style="line-height:25px"> 那么系统如何区分让当前activity退到background时使用是用户的choice?<br style="line-height:25px"> 它是根据促使当前activity退到background的那个新启动的Activity的Intent里<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">是否有FLAG_ACTIVITY_NO_USER_ACTION来确定的</span><wbr style="line-height:25px">。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">:<span style="color:#000080; line-height:25px">通过调用finish()使该activity销毁时不会调用该函数。</span><br style="line-height:25px"></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> </div> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>