搜档网
当前位置:搜档网 › Activity和Task

Activity和Task

Activity和Task
Activity和Task

android:allowTaskReparenting

用来标记Activity能否从启动的Task移动到有着affinity的Task(当这个Task进入到前台时)——“true”,表示能移动,“false”,表示它必须呆在启动时呆在的那个Task 里。

如果这个特性没有被设定,设定到元素上的allowTaskReparenting特性的值会应用到Activity上。默认值为“false”。

一般来说,当Activity启动后,它就与启动它的Task关联,并且在那里耗尽它的整个生命周期。当当前的Task不再显示时,你可以使用这个特性来强制Activity移动到有着affinity的Task中。典型用法是:把一个应用程序的Activity移到另一个应用程序的主Task 中。

例如,如果e-mail中包含一个web页的链接,点击它就会启动一个Activity来显示这个页面。这个Activity是由Browser应用程序定义的,但是,现在它作为e-mail Task的一部分。如果它重新宿主到Browser Task里,当Browser下一次进入到前台时,它就能被看见,并且,当e-mail Task再次进入前台时,就看不到它了。

Actvity的affinity是由taskAffinity特性定义的。Task的affinity是通过读取根Activity 的affinity决定。因此,根据定义,根Activity总是位于相同affinity的Task里。由于启动模式为“singleTask”和“singleInstance”的Activity只能位于Task的底部,因此,重新宿主只能限于“standard”和“singleTop”模式。

android:alwaysRetainTaskState

用来标记Activity所在的Task的状态是否总是由系统来保持——“true”,表示总是;“false”,表示在某种情形下允许系统恢复Task到它的初始化状态。默认值是“false”。

这个特性只针对Task的根Activity有意义;对其它Activity来说,忽略之。

一般来说,特定的情形如当用户从主画面重新选择这个Task时,系统会对这个Task进行清理(从stack中删除位于根Activity之上的所有Activivity)。典型的情况,当用户有一段时间没有访问这个Task时也会这么做,例如30分钟。

然而,当这个特性设为“true”时,用户总是能回到这个Task的最新状态,无论他们是如何启动的。这非常有用,例如,像Browser应用程序,这里有很多的状态(例如多个打开的Tab),用户不想丢失这些状态。

android:clearTaskOnLaunch

用来标记是否从Task中清除所有的Activity,除了根Activity外(每当从主画面重新启动时)——“true”,表示总是清除至它的根Activity,“false”表示不。默认值是“false”。这个特性只对启动一个新的Task的Activity(根Activity)有意义;对Task中其它的Activity 忽略。

当这个值为“true”,每次用户重新启动这个Task时,都会进入到它的根Activity中,不管这个Task最后在做些什么,也不管用户是使用BACK还是HOME离开的。当这个值为“false”时,可能会在一些情形下(参考alwaysRetainTaskState特性)清除Task的Activity,但不总是。

假设,某人从主画面启动了Activity P,并从那里迁移至Activity Q。接下来用户按下HOME,然后返回Activity P。一般,用户可能见到的是Activity Q,因为它是P的Task 中最后工作的内容。然而,如果P设定这个特性为“true”,当用户按下HOME并使这个Task再次进入前台时,其上的所有的Activity(在这里是Q)都将被清除。因此,当返回到这个Task时,用户只能看到P。

如果这个特性和allowTaskReparenting都设定为“true”,那些能重新宿主的Activity 会移动到共享affinity的Task中;剩下的Activity都将被抛弃,如上所述。

android:finishOnTaskLaunch

用来标记当用户再次启动它的Task(在主画面选择这个Task)时已经存在的Activity 实例是否要关闭(结束)——“true”,表示应该关闭,“false”表示不关闭。默认值是“false”。

如果这个特性和allowTaskReparenting都设定为“true”,这个特性胜出。Activity 的affinity忽略。这个Activity不会重新宿主,但是会销毁。

android:launchMode

用于指示Activity如何启动。这里有四种模式,与Intent对象中的Activity Flags (FLAG_ACTIVITY_*变量)共同作用,来决定Activity如何启动来处理Intent。它们是:

"standard"

"singleTop"

"singleTask"

"singleInstance"

默认模式是“standard”。

这些模式可以分成两大组别,“standard”和“singleTop”一组,“singleTask”和

“singleInstance”一组。具有“standard”和“singleTop”启动模式的Activity可以实例化很多次。这些实例可以属于任何Task并且可以位于Activity stack的任何位置。典型的情况是,它们会进入调用startActivity()的Task(除非Intent对象包含

FLAG_ACTIVITY_NEW_TASK标志,在这种情况下会选择一个不同的Task——参考taskAffinity特性)。

相反的,“singleTask”和“singleInstance”只能启动一个Task。它们总是位于Activity stack的底部。甚至,设备一次只能拥有一个Activity的实例——只有一个这样的Task。

“standard”和“singleTop”模式只在一种情况下有差别:每次有一个新的启动“standard”Activity的Intent,就会创建一个新的实例来响应这个Intent。每个实例处理一个Intent。相似的,一个“singleTop”的Activity实例也有可能被创建来处理新的Intent。然而,如果目标Task已经有一个存在的实例并且位于stack的顶部,那么,这个实例就会接收到这个新的Intent(调用onNewIntent());不会创建新的实例。在其他情况下——例如,如果存在的“singleTop”的Activity实例在目标Task中,但不是在stack 的顶部,或者它在一个stack的顶部,但不是在目标Task中——新的实例都会被创建并压入stack中。

“singleTask”和“singleInstance”模式也只在一种情况下有差别:“singleTask”Activity允许其它Activity成为它的Task的部分。它位于Activity stack 的底部,其它Activity(必须是“standard”和“singleTop”Activity)可以启动加入到相同的Task中。“singleInstance”Activity,换句话说,不允许其它Activity成为它的Task的部分。它是Task中的唯一Activity。如果它启动其它的Activity,这个Activity会被放置到另一个task中——好像Intent中包含了FLAG_ACTIVITY_NEW_TASK标志。

android:noHistory

用于标记当用户从Activity上离开并且它在屏幕上不再可见时Activity是否从Activity stack中清除并结束(调用finish()方法)——“true”,表示它应该关闭,“false”,表示不需要。默认值是“false”。

“true”值意味着Activity不会留下历史痕迹。因为它不会在Activity stack的Task中保留,因此,用户不能返回它。

android:taskAffinity

Activity为Task拥有的一个affinity。拥有相同的affinity的Activity理论上属于相同的Task(在用户的角度是相同的“应用程序”)。Task的affinity是由它的根Activity决定的。

affinity决定两件事情——Activity重新宿主的Task(参考allowTaskReparenting特性)和使用FLAG_ACTIVITY_NEW_TASK标志启动的Activity宿主的Task。

默认情况,一个应用程序中的所有Activity都拥有相同的affinity。捏可以设定这个特性来重组它们,甚至可以把不同应用程序中定义的Activity放置到相同的Task中。为了明确Activity不宿主特定的Task,设定该特性为空的字符串。

如果这个特性没有设置,Activity将从应用程序的设定那里继承下来(参考元素的taskAffinity特性)。应用程序默认的affinity的名字是元素中设定的package名。

FLAG_ACTIVITY_BROUGHT_TO_FRONT

这个标志一般不是由程序代码设置的,如在launchMode中设置singleTask模式时系

统帮你设定。

FLAG_ACTIVITY_CLEAR_TOP

如果设置,并且这个Activity已经在当前的Task中运行,因此,不再是重新启动一个这个Activity的实例,而是在这个Activity上方的所有Activity都将关闭,然后这个Intent 会作为一个新的Intent投递到老的Activity(现在位于顶端)中。

例如,假设一个Task中包含这些Activity:A,B,C,D。如果D调用了startActivity(),并且包含一个指向Activity B的Intent,那么,C和D都将结束,然后B接收到这个Intent,因此,目前stack的状况是:A,B。

上例中正在运行的Activity B既可以在onNewIntent()中接收到这个新的Intent,也可以把自己关闭然后重新启动来接收这个Intent。如果它的启动模式声明为“multiple”(默认值),并且你没有在这个Intent中设置FLAG_ACTIVITY_SINGLE_TOP标志,那么它将关闭然后重新创建;对于其它的启动模式,或者在这个Intent中设置

FLAG_ACTIVITY_SINGLE_TOP标志,都将把这个Intent投递到当前这个实例的onNewIntent()中。

这个启动模式还可以与FLAG_ACTIVITY_NEW_TASK结合起来使用:用于启动一个Task 中的根Activity,它会把那个Task中任何运行的实例带入前台,然后清除它直到根Activity。这非常有用,例如,当从Notification Manager处启动一个Activity。

FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

如果设置,这将在Task的Activity stack中设置一个还原点,当Task恢复时,需要清理Activity。也就是说,下一次Task带着FLAG_ACTIVITY_RESET_TASK_IF_NEEDED标

记进入前台时(典型的操作是用户在主画面重启它),这个Activity和它之上的都将关闭,以至于用户不能再返回到它们,但是可以回到之前的Activity。

这在你的程序有分割点的时候很有用。例如,一个e-mail应用程序可能有一个操作是查看一个附件,需要启动图片浏览Activity来显示。这个Activity应该作为e-mail应用程序Task的一部分,因为这是用户在这个Task中触发的操作。然而,当用户离开这个Task,然后从主画面选择e-mail app,我们可能希望回到查看的会话中,但不是查看图片附件,因为这让人困惑。通过在启动图片浏览时设定这个标志,浏览及其它启动的Activity在下次用户返回到mail程序时都将全部清除。

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结合起来使用,可以禁用把已存的Task送入前台的行为。当设置时,新的Task总是会启动来处理Intent,而不管这是是否已经有一个Task可以处理相同的事情。

由于默认的系统不包含图形Task管理功能,因此,你不应该使用这个标志,除非你提供给用户一种方式可以返回到已经启动的Task。

如果FLAG_ACTIVITY_NEW_TASK标志没有设置,这个标志被忽略。

FLAG_ACTIVITY_NEW_TASK

如果设置,这个Activity会成为历史stack中一个新Task的开始。一个Task(从启动它的Activity到下一个Task中的Activity)定义了用户可以迁移的Activity原子组。Task 可以移动到前台和后台;在某个特定Task中的所有Activity总是保持相同的次序。

这个标志一般用于呈现“启动”类型的行为:它们提供用户一系列可以单独完成的事情,与启动它们的Activity完全无关。

使用这个标志,如果正在启动的Activity的Task已经在运行的话,那么,新的Activity 将不会启动;代替的,当前Task会简单的移入前台。参考FLAG_ACTIVITY_MULTIPLE_TASK 标志,可以禁用这一行为。

这个标志不能用于调用方对已经启动的Activity请求结果。

FLAG_ACTIVITY_NO_ANIMATION

如果在Intent中设置,并传递给Context.startActivity()的话,这个标志将阻止系统进入下一个Activity时应用Acitivity迁移动画。这并不意味着动画将永不运行——如果另一

个Activity在启动显示之前,没有指定这个标志,那么,动画将被应用。这个标志可以很好的用于执行一连串的操作,而动画被看作是更高一级的事件的驱动。

FLAG_ACTIVITY_NO_HISTORY

如果设置,新的Activity将不再历史stack中保留。用户一离开它,这个Activity就关闭了。这也可以通过设置noHistory特性。

FLAG_ACTIVITY_NO_USER_ACTION

如果设置,作为新启动的Activity进入前台时,这个标志将在Activity暂停之前阻止从最前方的Activity回调的onUserLeaveHint()。

典型的,一个Activity可以依赖这个回调指明显式的用户动作引起的Activity移出后台。这个回调在Activity的生命周期中标记一个合适的点,并关闭一些Notification。

如果一个Activity通过非用户驱动的事件,如来电或闹钟,启动的,这个标志也应该传递给Context.startActivity,保证暂停的Activity不认为用户已经知晓其Notification。

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

如果在Intent中设置,并传递给Context.startActivity(),这个标志将引发已经运行的Activity移动到历史stack的顶端。

例如,假设一个Task由四个Activity组成:A,B,C,D。如果D调用startActivity()来启动Activity B,那么,B会移动到历史stack的顶端,现在的次序变成A,C,D,B。如果FLAG_ACTIVITY_CLEAR_TOP标志也设置的话,那么这个标志将被忽略。

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位于历史stack的顶端运行时,不再启动一个新的。Activity和Task

之前提到的,一个Activity可以启动另一个,即便是定义在不同应用程序中的Activity。例如,假设你想让用户显示一些地方的街景。而这里已经有一个Activity可以做到这一点,因此,你的Activity所需要做的只是在Intent对象中添加必要的信息,并传递给startActivity()。地图浏览将会显示你的地图。当用户按下BACK键,你的Activity会再次出现在屏幕上。

对于用户来说,看起来好像是地图浏览与你的Activity一样,属于相同的应用程序,即便是它定义在其它的应用程序里,并运行在那个应用程序的进程里。Android通过将这两个Activity保存在同一个Task里来体现这一用户体验。简单来说,一个Task就是用户体验上的一个“应用”。它将相关的Activity组合在一起,以stack的方式管理。stack中根Activity启动Task——典型的,它就是用户在应用程序启动栏中选择的Activity。位于stack 顶端的Activity是当前正在运行的——能够聚焦用户的动作。当一个Activity启动另一个,新的Activity进入stack;它成为正在运行的Activity。之前的Activity仍保留在stack中。当用户按下BACK键,当前的Activity从stack中退出,之前的那个成为正在运行的Activity。

stack包含对象,因此,如果一个Task中有多个同一个Activity的实例时——多个地图浏览,例如——stack为每个实例拥有一个独立的入口。位于stack中的Activity不会重新调整,只是进入和退出。

一个Task就是一组Activity,不是一个类或者在manifest中定义的一个元素。因此,没有办法为Task设置独立于它的Activity的属性值。Task的值作为整体在根Activity中设置。例如,下一个章节会讨论Task的“affinity”;那个值就是从Task中的根Activity中读取的。

Task中的所有Activity作为一个单元一起移动。整个Task(整个Activity stack)可以进入前台或者退到后台。例如,假设当前Task中的stack中有4个Activity——3个位于当前Activity下方。用户按下HOME键,进入到应用程序启动栏,然后选择一个新的应用程序(实际上,一个新的Task)。当前Task退到后台,并且新Task中的根Activity会显示出来。然后,经过一段时间后,用户回到Home画面,然后再次选择前一个应用程序(前一个Task)。那个拥有4个Activity的Task会进入前台。当用户按下BACK键,屏幕不会显示用户刚刚离开的Activity(前一个Task的根Activity)。而是,这个stack中的顶端Activity移除,相同Task中的前一个Activity会显示出来。

刚才描述的行为是Activity和Task的默认行为。但有方法来完全改变它。Task之间的关联,和一个Task中的一个Activity行为,受启动Activity的Intent对象中设置的Flag和manifest文件中Activity的元素的特性值交互控制。调用者和响应者都有权决定如何发生。

核心的Intent Flag有:

FLAG_ACTIVITY_NEW_TASK

FLAG_ACTIVITY_CLEAR_TOP

FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

FLAG_ACTIVITY_SINGLE_TOP

核心的特性有:

taskAffinity

launchMode

allowTaskReparenting

clearTaskOnLaunch

alwaysRetainTaskState

finishOnTaskLaunch

接下来的章节将描述一些Flag和特性的用法,如何相互影响,以及在使用时的建议。

Affinity和新Task

默认情况下,一个应用程序中的所有Activity都有affinity——也就是说,属于同一个Task 中所有Activity有一个设定。然而,每个Activity都可以在元素的taskAffinity 特性上设置单独的值。定义在不同应用程序中的Activity可以共享同一个affinity,或者定义在同一个应用程序中的Activity设置不同的affinity。Affinity在两种环境下工作:Intent 对象包含FLAG_ACTIVITY_NEW_TASK标志,和Activity的allowTaskReparenting特性设置为“true”。

FLAG_ACTIVITY_NEW_TASK:

之前描述的,一个Activity一般通过调用startActivity()启动并加入到Task中。它同调用者一样,进入同一个Task。然而,如果传递给startActivity()的Intent对象中包含FLAG_ACTIVITY_NEW_TASK时,系统会搜索一个新的Task来容纳新的Activity。

通常,如标志的名字所示,是一个新的Task。然而,并不是必须是。如果已经存在一

个Task与新Activity的affinity相同,这个Activity就会加入到那个Task中。如果不是,启动一个新的Task。

allowTaskReparenting:

如果一个Activity的allowTaskReparenting特性设置为“true”,它就能从启动的Task中移到有着相同affinity的Task(这个Task进入到前台的时候)。例如,在一个旅游的程序中定义了一个可以报告选择城市的天气情况的Activity。它和同一个应用程序的其它Activity一样,有着相同的Affinity(默认的Affinity),并且它允许重新宿主。你的Activity中的一个启动了天气预报,因此,它初始化到和你Activity相同的Task中。然而,当旅游应用程序下一次进入到前台时,天气预报那个Activity将会重新编排并在那个Task中显示。

如果从用户的角度出发,一个.apk文件包含多个“应用”的话,你可能希望为关联的Activity 设置不同的affinity。

Launch Mode

这里4种不同的启动模式可以设置到元素的launchMode特性上:standard(默认模式)

singleTop

singleTask

singleInstance

这些模式有以下四点区别:

l 哪个Task将容纳响应Intent的Activity。对于“standard”和“singleTop”来说,是产生Intent的那个Task(并调用startActivity())——除非Intent对象包含

FLAG_ACTIVITY_NEW_TASK。在那种情况下,不同的Task将被选择,如“Affinity 和新Task”中描述的那样。对比而言,“singleTask”和“singleInstance”指示Activity 总是一个Task的根。它们定义一个Task;它们不会加入到另一个Task中。

l 是否有多个Activity的实例。“standard”和“singleTop”可以实例化多次。它们可以属于多个Task,一个特定的Task可以有相同Activity的多个实例。对比而言,

“singleTask”和“singleInstance”只能有一个实例。因为这些Activity只能位于Task的底部,这一限制意味着在设备的某个时间,不会出现这样Task的多个实例。l 是否可以在同一个Task中拥有其它的Activity。“singleInstance”Activity保持单身,在它的Task中它是仅有的Activity。如果它启动另一个Activity,那个Activity将会放入到不同的Task中,而不管它的启动模式——好像FLAG_ACTIVITY_NEW_TASK 在Intent中一样。对于其它方面,,“singleInstance”等同于“singleTask”。其它三个模式允许多个Activity加入到这个Task中。“singleTask”Activity总是位于Task的底部,但它可以启动其它的Activity并放入到它的Task中。“standard”和“singleTop”的Activity可以出现在stack的任何地方。

l 是否一个新的实例启动来处理新的Intent。对于默认的“standard”来说,都是创建一个新的实例来响应新的Intent。每个实例处理一个Intent。对于“singleTop”来说,如果它位于目标Task的顶端,那么,已经存在的实例就可以重复使用来处理这个新的Intent。如果它不在顶端,那么它就不能重复使用。替代的,新的实例将创建来响应新的Intent,并进入到stack中。

例如,假设一个Task的Activity stack中包含根Activity A和其它Activity B,C,D,并且D位于顶端,因此,stack是A-B-C-D。有一个Intent来了,它要启动D类型的Activity。如果D有默认的“standard”启动模式,那么,一个新的实例将被启动并且stack变成A-B-C-D-D。然而,如果D的启动模式“singleTop”,已经存在的实例将去处理新来的Intent(因为它正好处在stack的顶端),并且stack依旧是A-B-C-D。

换句话说,如果来临的Intent是冲着B类型的,那么,B类型的实例将被创建启动而不管B的模式是“standard”或“singleTop”(因为B不处在stack的顶端),因此,stack将会是A-B-C-D-B。

之前提到的,设备上不会出现超过一个实例的“singleTask”或“singleInstance”

Activity,因此,那个实例都将去处理所有新来的Intent。“singleInstance”Activity 总是位于stack的顶端(因为它是task中唯一的Activity),因此,它总是处于能处理Intent的位置。然而,“singleTask”Activity可能有或没有其它Activity处于它的上方。如果有,它就不处于能处理Intent的位置,那么,这个Intent将被丢弃。(即使Intent被丢弃了,它的到来会引发那个Task进入到前台,在那里,它会继续保留。)

当一个存在的Activity请求去处理一个新的Intent时,Intent对象将传到该Activity的onNewIntent()的方法中。(原来启动Activity的Intent对象可以通过调用getIntent()得到。)

注意:当一个新的实例创建来处理新的Intent时,用户可以按下BACK键返回到之前的状态(前一个Activity)。但一个存在的实例来处理新的Intent时,用户不能按下BACK键返回到新Intent到来之前的状态。

清除stack

如果用户离开Task很长一段时间,系统会清除Task中的所有Activity,除根Activity外。当用户再次返回到这个Task时,和用户离开时一样,仅仅只是初始化Activity呈现。这样做的意图是,经过一些时间后,用户可能已经忘记之前正在做的事情,并且打算回到Task 开始些新的时期。

这是默认情况。这里有一些Activity特性可以用于控制这一行为并且修改它:alwaysRetainTaskState:

如果Task的根Activity的这个特性设置为“true”时,上面描述的默认行为不会发生。

Task保留所有的Activity,即便是经过很长一段时间。

clearTaskOnLaunch:

如果Task的根Activity的这个特性设置为“true”时,当用户离开Task并返回时,stack会清除直到根Activity。换句话说,它是alwaysRetainTaskState的另一个极端。

用户总是回到Task的初始化状态,即便是一个短暂的离开。

finishOnTaskLaunch:

这个特性和clearTaskOnLaunch相似,但它针对单个Activity,不是整个Task。它能使任何Activity消失,包括根Activity。当它设置为“true”时,这个Activity仅在当前会话期间保持为Task的部分。如果用户离开并再次返回到这个Task,它就不再显示了。

这里还有其它的方式可以强制Activity从stack中移除。如果Intent对象中包含

FLAG_ACTIVITY_CLEAR_TOP标志,并且目标Task中已经有一个这个类型Activity的实例,而且这个实例应该处理这个Intent,那么,位于其上的Activity都将移除,这样,这个Activity就能在stack的顶端并响应这个Intent。如果这个Activity的启动模式设定为“standard”,它也会从stack中清除,然后新的实例启动来响应这个Intent。这是因为当启动模式设定为“standard“时,总是会创建一个新的实例来响应新的Intent。

FLAG_ACTIVITY_CLEAR_TOP经常与FLAG_ACTIVITY_NEW_TASK结合起来使用。当一起使用时,这些标志可以定位其它Task中已经存在的Activity,并且把它置于可以响应Intent的位置。

启动Task

如果一个Activity的Intent Filter的action为“android.intent.action.MAIN”、category 为“https://www.sodocs.net/doc/a011688093.html,UNCHER”时,它就可以作为一个Task的入口点。有这种类型的Filter会在导致这个Activity在应用程序启动栏显示一个图标和标签,给用户提供一个方式可以启动这个Task和在任何时候可以再次回到这个Task。

第二个能力很重要:用户一定可以离开一个Task,然后可以再次回到它。基于这个原因,两个启动模式,“singleTask”和“singleInstance”应该只在有MAIN和LAUNCHER的Activity上使用。例如,假设这个Filter没有的话:一个Intent启动了一个“singleTask”Activity,初始化一个新的Task,然后用户花费了一些时间在它上面。然后,用户按下HOME

键。现在,这个Task处于后台并且被HOME画面遮盖。由于它不能在应用程序启动栏显示,用户就没有办法可以返回它。

在面对FLAG_ACTIVITY_NEW_TASK时,也有相似的困难。如果这个标志导致一个Activity 启动了一个新的Task,并且用户按下HOME键离开它,这里必须有方法可以再次回到它。一些机能(如Notification Manager)总是在外部的Task中启动Activity,而不是作为自己的一部分,因此,它总是把FLAG_ACTIVITY_NEW_TASK标志放入Intent,然后传递给startActivity()。如果你的Activity可能会被外部的机能(可能使用这个标志)调用,注意用户可以额外的方式可以返回到启动的Task。

如果你不想用户回到某个Activity,可以把元素的finishOnTaskLaunch设置为“true”。

面试官必问的16个经典问题回答

如何能面试成功,有一定的技巧,因为面试都有一个共性,那就是考察求职者的反应能力和临时语言组织能力,不过,这些都是可以训练的,而且有章可循的,只要你掌握了其中的技巧,便可百战百胜啦。 当然了解面试官的想法是非常必要的,本文对面试中经常出现的一些典型问题进行了归纳和整理,并给出相应的回答和参考。你无需过分关注分析的细节,关键是要从这些分析中“悟”出面试的规律及回答问题的思维方式,达到“活学活用”。 问题一:“请你自我介绍一下” 1、这是面试的必考题目。 2、介绍内容要与个人简历相一致。 3、表述方式上尽量口语化。 4、要切中要害,不谈无关、无用的内容。 5、条理要清晰,层次要分明。 6、事先最好以文字的形式写好背熟。 问题二:“谈谈你的家庭情况” 1、家庭情况对于了解应聘者的性格、观念、心态等有一定的作用,这是招聘单位问该问题的主要原因。 2、简单地罗列家庭人口。 3、宜强调温馨和睦的家庭氛围。 4、宜强调父母对自己教育的重视。 5、宜强调各位家庭成员的良好状况。 6、宜强调家庭成员对自己工作的支持。 7、宜强调自己对家庭的责任感。 问题三:“你有什么业余爱好?”

1、业余爱好能在一定程度上反映应聘者的性格、观念、心态,这是招聘单位问该问题的主要原因。 2、最好不要说自己没有业余爱好。 3、不要说自己有那些庸俗的、令人感觉不好的爱好。 4、最好不要说自己仅限于读书、听音乐、上网,否则可能令面试官怀疑应聘者性格孤僻。 5、最好能有一些户外的业余爱好来“点缀”你的形象。 问题四:“你最崇拜谁?” 1、最崇拜的人能在一定程度上反映应聘者的性格、观念、心态,这是面试官问该问题的主要原因。 2、不宜说自己谁都不崇拜。 3、不宜说崇拜自己。 4、不宜说崇拜一个虚幻的、或是不知名的人。 5、不宜说崇拜一个明显具有负面形象的人。 6、所崇拜的人人最好与自己所应聘的工作能“搭”上关系。 7、最好说出自己所崇拜的人的哪些品质、哪些思想感染着自己、鼓舞着自己。 问题五:“你的座右铭是什么?” 1、座右铭能在一定程度上反映应聘者的性格、观念、心态,这是面试官问这个问题的主要原因。 2、不宜说那些医引起不好联想的座右铭。 3、不宜说那些太抽象的座右铭。 4、不宜说太长的座右铭。

1997年全国硕士研究生入学统一考试英语一试题及解析

1997年全国硕士研究生入学统一考试英语试题 Section II Cloze Test Directions: For each numbered blank in the following passage, there are four choices marked [A], [B], [C], and [D]. Choose the best one and mark your answer on the ANSWER SHEET 1 by blackening the corresponding letter in the brackets. (10 points) Manpower Inc., with 560,000 workers, is the world’s largest temporary employment agency. Every morning, its people 41into the offices and factories of America, seeking a day’s work for a day’s pay. One da y at a time. 42industrial giants like General Motors and IBM struggle to survive 43reducing the number of employees, Manpower, based in Milwaukee, Wisconsin, is booming. 44its economy continues to recover, the US is increasingly becoming a nation of part-timers and temporary workers. This “45” work force is the most important 46in American business today, and it is 47changing the relationship between people and their jobs. The phenomenon provides a way for companies to remain globally competitive 48avoiding market cycles and the growing burdens 49by employment rules, healthcare costs and pension plans. For workers it can mean an end to the security, benefits and sense of 50 that came from being a loyal employee. 41. [A] swarm [B] stride [C] separate [D] slip 42. [A] For [B] Because [C] As [D] Since 43. [A] from [B] in [C] on [D] by 44. [A] Even though [B] Now that [C] If only [D] Provided that 45. [A] durable [B] disposable [C] available [D] transferable

2019英语硕士研究生入学考试英语一真题及答案

2019年全国硕士研究生入学考试英语一真题及答案 Section ⅠUse of English Directions: Read the following text. Choose the best word(s) for each numbered blank and mark A, B, C or D on the ANSWER SHEET. (10 points) Today we live in a world where GPS systems, digital maps, and other navigation apps are available on our smart phones. 1 of us just walk straight into the woods without a phone. But phones 2 on batteries, and batteries can die faster than we realize. 3 you get lost without a phone or a compass, and you 4 can’t find north, a few tricks to help you navigate 5 to civilization, one of which is to follow the land... When you find yourself well 6 a trail, but not in a completely 7 area, you have to answer two questions: Which 8 is downhill, in this particular area? And where is the nearest water source? Humans overwhelmingly live in valleys, and on supplies of fresh water. 9 , if you head downhill, and follow any H2O you find, you should 10 see signs of people. If you’ve explored the area before, keep an eye out for familiar sights—you may be 11 how quickly identifying a distinctive rock or tree can restore your bearings. Another 12 : Climb high and look for signs of human habitation. 13 , even in dense forest, you should be able to 14 gaps in the tree line due to roads, train tracks, and other paths people carve 15 the woods. Head toward these 16 to find a way out. At night, scan the horizon for 17 light sources, such as fires and streetlights, then walk toward the glow of light pollution. 18 , assuming you’re lost in an area humans tend to frequent, look for the 19 we leave on the landscape. Trail blazes, tire tracks, and other features can 20 you to civilization.

各种复试英语问题集锦(应试方法自我介绍模板面试官常问问题)

荟萃精品11条:考研复试英语自我介绍不再愁 自我介绍英语,英文自我介绍 Sample1: My name is ________. I am graduated from ________ and major in ________. There are ________ people in my family. My father works in a computer company. And my mother is a housewife. I am the youngest one in my family. In my spare time, I like to read novels. I think reading could enlarge my knowledge. In addition to reading, I also like to play PC games. A lot of grownups think playing PC games hinders the students from learning. But I think PC games could motivate me to learn something such as English or Japanese. My favorite course is English because I think it is interesting to say one thing via different sounds. I wish my English could be improved in the next four years and be able to speak fluent English in the future. Sample2: I am ________. I was born in ________. I graduate from ________ and major in English. I started learning English since I was 12 years old. My parents have a lot of American friends. That’s why I have no problem communicatin g with Americans or others by speaking English. In my spare time, I like to do anything relating to English such as listening to English songs, watching English movies or TV programs, or even attending the activities held by some English clubs or institutes. I used to go abroad for a short- term English study. During that time, I learned a lot of daily life English and saw a lot of different things. I think language is very interesting. I could express one substance by using different sounds. So I wish I could study and read more English literatures and enlarge my knowledge. Sample3: My name is ________. There are 4 people in my family. My father is a Chemistry teacher. He teaches chemistry in ________ senior high school. My mother is an English teacher. She teaches English in the university. I have a younger brother,

面试题目及其答案大全

android面试题目及其答案大全 1,++i和i++ 区别 2,makefile文件代码,写代码 3,隐藏与重写的区别 4,linux 基本命令使用如:如何查询帮助文档(man),如何查处文件(fiind),常用命令5,进程间通信有几种,效率如何 6、什么是嵌入式实时操作系统, Android 操作系统属于实时操作系统吗? 7,tcp/ip 有几层 8、一条最长的短信息约占多少byte? 9,p2p 和SMTP分别在哪层 10、android中的动画有哪几类,它们的特点和区别是什么? 11,多态概念(父类引用子类参数) 12、handler机制的原理 13,java 写1+N的和 14,数据结构与算法如排序,二叉树 15,MVC概念(为什么有DAO层,什么作用) 16,GC回收机制 17、说说mvc模式的原理,它在android中的运用 18,android项目自述 19,java 的进程与线程维护 20、Activity的生命周期 21,N*N 打印出来的样子是(例如N=4) 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 22,linux 末行,输入,命令三个模式 23、Android dvm的进程和Linux的进程, 应用程序的进程是否为同一个概念 24,android 四层架构分别的作用(android系统框图) 25、sim卡的EF 文件有何作用 26,android四大组件,生命周期,onpause()与onstop()的区别 27,UMI建模概念 28,C语言打印N*N数组,规律如下: 2维 1 2 3 4 3维 1 2 3 8 9 4 7 6 5 4维 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7

2015年全国硕士研究生招生考试英语(一)试题(完整版)及参考答案

2015 年全国硕士研究生入学统一考试英语一试题Section 1 Use of English Directions: Read the following text. Choose the best word(s) for each numbered blank and mark [A], [B], [C] or [D] on ANSWER SHEET 1. (10 points) Though not biologically related, friends are as related as fourth cousins, sharing about 1% of genes. That is 1 a study published from the University of California and Yale University in the Proceedings of the National Academy of Sciences, has 2 . The study is a genome-wide analysis conducted 3 1932 unique subjects which 4 pairs of unrelated friends and unrelated strangers. The same people were used in both 5 .While 1% may seem 6 , it is not so to a geneticist. As James Fowler, professor of medical genetics at UC San Diego, says, Most people do not even 7 their fourth cousins but somehow manage to select as friends the people who 8 our kin. The study 9 found that the genes for smell were something shared in friends but not genes for immunity. Why this similarity in olfactory genes is difficult to explain, for now. 10 Perhaps, as the team suggests, it draws us to similar environments but there is more 11 it. There could be many mechanisms working in tandem that 12 us in choosing genetically similar friends 13 than nal kinship of being friends with 14 !One of the remarkable

常见面试必问23题(仅参考未整理答案)

Android开发中常见的一些问题面试专题 1.ListView 中图片错位的问题是如何产生的? 2.混合开发有了解吗? 3.知道哪些混合开发的方式?说出它们的优缺点和各自使用场景?(解答:比如:RN,weex, 4.H5,小程序,WPA等。做Android的了解一些前端js等还是很有好处的); 5.屏幕适配的处理技巧都有哪些? 6.服务器只提供数据接收接口,在多线程或多进程条件下,如何保证数据的有序到达? 7.动态布局的理解 8.怎么去除重复代码? 9.画出Android 的大体架构图 10Recycleview和ListView的区别 11. ListView图片加载错乱的原理和解决方案 ListView item缓存机制:为了使得性能更优,ListView会缓存行item(某行对应的View)。ListView通过adapter的getView函数获得每行的item。 滑动过程中 1)如果某行item已经滑出屏幕,若该item不在缓存内,则put进缓存,否则更新缓存; 2)获取滑入屏幕的行item之前会先判断缓存中是否有可用的item,如果有,做为convertView参数传递给adapter的getView。 出现的问题: 1)行item图片显示重复,当前行item显示了之前某行item的图片。 比如ListView滑动到第2行会异步加载某个图片,但是加载很慢,加载过程中listView已经滑动到了第14行,且滑动过程中该图片加载结束,第2行已不在屏幕内,根据上面介绍的缓存原理,第2行的view可能被第14行复用,这样我们看到的就是第14行显示了本该

属于第2行的图片,造成显示重复。 2)行item图片显示闪烁 如果第14行图片又很快加载结束,所以我们看到第14行先显示了第2行的图片,立马又显示了自己的图片进行覆盖造成闪烁错乱。 解决方法 通过上面的分析我们知道了出现错乱的原因是异步加载及对象被复用造成的,如果每次getView能给对象一个标识,在异步加载完成时比较标识与当前行item的标识是否一致,一致则显示,否则不做处理即可。 12.动态权限适配方案,权限组的概念 13.Android系统为什么会设计ContentProvider? 14.下拉状态栏是不是影响activity的生命周期 15.如果在onStop的时候做了网络请求,onResume的时候怎么恢复? 16.Bitmap 使用时候注意什么? 17.Bitmap的recycler() 18.Android中开启摄像头的主要步骤 19.ViewPager使用细节,如何设置成每次只初始化当前的Fragment,其他的不初始化? 20.点击事件被拦截,但是想传到下面的View,如何操作? 21.微信主页面的实现方式 22.微信上消息小红点的原理 23.CAS介绍

2020年全国硕士研究生招生考试英语一(带答案)

2020年全国硕士研究生招生考试英语一 Section I Use of English (红色字体为参考答案) 以下真题及答案由聚创考研网收集整理,仅供参考,如有出入请以教育部公布的权威答案和解析为准! Directions: Read the following text. Choose the best word(s) for each numbered blank and mark [A], [B], [C], or [D] on the ANSWER SHEET. (10 points) Even if families don’t sit down to eat together as frequently as before, millions of Britons will nonetheless have got a share this weekend of one of that nation’s great traditions: the Sunday roast. 1 a cold winter’s day,few culinary pleasures can 2 it. Yet as we report now,the food police are determined our health that this 3 should be rendered yet another guilty pleasure 4 to damage our health. The Food Standards Authority (FSA) has 5 a public warning about the risks of a compound called acrylamide that forms in some foods cooked 6 high temperatures. This

面试必须问的七个问题

The 7 Interview Questions You Must Ask 面试中必须问的七个问题 There are no magic bullets when it comes to job interview questions, but the way you structure your queries is important: It's the interviewer's job to create a framework for the discussion and prevent it from running off the rails. Every company's needs are different, but a good basic strategy is to ground the interview in questions about past job performance. Then throw in some situational questions to evaluate practical decision making, and learn a little bit about how the job fits in with a candidate's biography. Question #1: "How about those Yankees?" Purpose: Develop the rapport needed to get the interview off the ground. Every interview should begin with an icebreaker. It helps nervous applicants calm down and builds a sense of trust. If you have a 45-minute interview, you should spend at least the first five minutes trying to connect on a neutral topic. Make the person feel at ease and you'll solicit better information—and much more honest responses. Alternate Version 1: "Did you go to the industry conference last week?" Alternate Version 2: "Were you affected by the heat wave/cold snap?" Question #2: "Talk about a time when you had to overcome major obstacles." Purpose: Get a clear picture of the candidate's past performance. Variations on this question should actually comprise your next several questions. Don't hesitate to guide the candidate through the variety of tasks (both tangible and theoretical)

全国硕士研究生入学统一考试英语一试题及解析

2001年全国硕士研究生入学统一考试英语试题 Section II Cloze Test Directions: For each numbered blank in the following passage, there are four choices marked [A], [B], [C] and [D]. Choose the best one and mark your answer on ANSWER SHEET 1 by blackening the corresponding letter in the brackets with a pencil. (10 points) The government is to ban payments to witnesses by newspapers seeking to buy up people involved in prominent cases 31the trial of Rosemary West. In a significant 32of legal controls over the press, Lord Irvine, the Lord Chancellor, will introduce a 33bill that will propose making payments to witnesses 34and will strictly control the amount of 35that can be given to a case 36 a trial begins. In a letter to Gerald Kaufman, chairman of the House of Commons Media Select Committee, Lord Irvine said he 37with a committee report this year which said that self regulation did not 38 sufficient control. 39of the letter came two days after Lord Irvine caused a 40of media protest when he said the 41of privacy controls contained in European legislation would be left to judges 42 to Parliament. The Lord Chancellor said introduction of the Human Rights Bill, which 43the European Convention on Human Rights legally 44in Britain, laid down that everybody was 45to privacy and that public figures could go to court to protect themselves and their families. “Press freedoms will be in safe hands 46our British judges,” he said. Witness payments became an 47after West was sentenced to 10 life sentences in 1995. Up to 19 witnesses were 48to have received payments for telling their stories to newspapers. Concerns were raised 49witnesses might be encouraged to exaggerate their stories in court to 50 guilty verdicts. 31. [A] as to [B] for instance [C] in particular [D] such as 32. [A] tightening [B] intensifying [C] focusing [D] fastening

面试时必问的100个问题技巧性回答

1、请你自我介绍一下你自己? 回答提示:一般人回答这个问题过于平常,只说姓名、年龄、爱好、工作经验,这些在简历上都有。其实,企业最希望知道的是求职者能否胜任工作,包括:最强的技能、最深入研究的知识领域、个性中最积极的部分、做过的最成功的事,主要的成就等,这些都可以和学习无关,也可以和学习有关,但要突出积极的个性和做事的能力,说得合情合理企业才会相信。企业很重视一个人的礼貌,求职者要尊重考官,在回答每个问题之后都说一句“谢谢”,企业喜欢有礼貌的求职者。 2、你觉得你个性上最大的优点是什么? 回答提示:沉着冷静、条理清楚、立场坚定、顽强向上、乐于助人和关心他人、适应能力和幽默感、乐观和友爱。我在北大青鸟经过一到两年的培训及项目实战,加上实习工作,使我适合这份工作。 3、说说你最大的缺点? 回答提示:这个问题企业问的概率很大,通常不希望听到直接回答的缺点是什么等,如果求职者说自己小心眼、爱忌妒人、非常懒、脾气大、工作效率低,企业肯定不会录用你。绝对不要自作聪明地回答“我最大的缺点是过于追求完美”,有的人以为这样回答会显得自己比较出色,但事实上,他已经岌岌可危了。企业喜欢求职者从自己的优点说起,中间加一些小缺点,最后再把问题转回到优点上,突出优点的部分,企业喜欢聪明的求职者。 4、你对加班的看法? 回答提示:实际上好多公司问这个问题,并不证明一定要加班,只是想测试你是否愿意为公司奉献。 回答样本:如果是工作需要我会义不容辞加班,我现在单身,没有任何家庭负担,可以全身心的投入工作。但同时,我也会提高工作效率,减少不必要的加班。 5、你对薪资的要求? 回答提示:如果你对薪酬的要求太低,那显然贬低自己的能力;如果你对薪酬的要求太高,那又会显得你分量过重,公司受用不起。一些雇主通常都事先对求聘的职位定下开支预算,因而他们第一次提出的价钱往往是他们所能给予的最高价钱,他们问你只不过想证实一下这笔钱是否足以引起你对该工作的兴趣。 回答样本一:我对工资没有硬性要求,我相信贵公司在处理我的问题上会友善合理。我注重的是找对工作机会,所以只要条件公平,我则不会计较太多。 回答样本二:我受过系统的软件编程的训练,不需要进行大量的培训,而且我本人也对编程特别感兴趣。因此,我希望公司能根据我的情况和市场标准的水平,给我合理的薪水。回答样本三:如果你必须自己说出具体数目,请不要说一个宽泛的范围,那样你将只能得到最低限度的数字。最好给出一个具体的数字,这样表明你已经对当今的人才市场作了调查,知道像自己这样学历的雇员有什么样的价值。

2020年全国硕士研究生考研英语一真题及答案详细解析

2020年全国硕士研究生考研英语一真题及答案详细解析 Section I Use of English Directions: Read the following text. Choose the best word (s) for each numbered blank and mark A, B, C or D on the ANSWER SHEET. (10 points) Even if families don't sit down to eat together as frequently as before, millions of Britons will nonetheless have got a share this weekend of one of that nation's great traditions; the Sunday roast. __1__ a cold winter's day, few culinary pleasures can 2 it. Yet as we report now, the food police are determined our health. That this__3__should be rendered yet another guilty pleasure __4__ to damage our health. The Food Standards Authority (FSA) has __5__ a public warning about the risks of a compound called acrylamide that forms in some foods cooked __6__ high temperatures. This means that people should __7__ crisping their roast potatoes, spurn thin-crust pizzas and only __8__ toast their bread. But where is the evidence to support such alarmist advice? __9__ studies have shown that acrylamide can cause neurological damage in mice, there is no __10__ evidence that it causes cancer in humans. Scientists say the compound is "__11__ to be carcinogenic" but have no hard scientific proof. __12__ the precautionary principle, it could be argued that it is __13__ to follow the FSA advice. __14__, it was rumored that smoking caused cancer for years before the evidence was found to prove a __15__. Doubtless a piece of boiled beef can always be __16__ up on Sunday alongside some steamed vegetables, without the Yorkshire pudding and no wine. But would life be worth living? __17__, the FSA says it is not telling people to cut out roast foods __18__, but to reduce their lifetime intake. However, their __19__ risks coming across as exhortation and nannying. Constant health scares just __20__ with no one listening. 1. [A] In [B] Towards [C] On [D] Till 2. [A] match [B] express [C] satisfy [D] influence 3. [A] patience [B] enjoyment [C] surprise [D] concern 4. [A] intensified [B] privileged [C] compelled [D] guaranteed 5. [A] issued [B] received [C] ignored [D] canceled 6. [A] under [B] at [C] for [D] by 7. [A] forget [B] regret [C] finish [D] avoid 8. [A] partially [B] regularly [C] easily [D] initially 9. [A] Unless [B] Since [C] If [D] While 10. [A] secondary [B] external [C] inconclusive [D] negative 11. [A] insufficient [B] bound [C] likely [D] slow 12. [A] On the basis of [B] At the cost of [C] In addition to [D] In contrast to 13. [A] interesting [B] advisable [C] urgent [D] fortunate 14. [A] As usual [B] In particular [C] By definition [D] After all 15. [A] resemblance [B] combination [C] connection [D] pattern 16. [A] made [B] served [C] saved [D] used 17. [A] To be fair [B] For instance [C] To be brief [D] in general 18. [A] reluctantly [B] entirely [C] gradually [D] carefully 19. [A] promise [B] experience [C] campaign [D] competition 20. [A] follow up [B] pick up [C] open up [D] end up

英语作文(研究生)英语一

Unit1 Individuality and privacy Everyone has his own Individuality and privacy,Nowadays, individuality has become a popular term with young people. But what is individuality? It is being different from others not only in outside appearance, but also in inner behavior. On the other hand, privacy is important. Everyone need privacy like you can’t just break into some random people’s house any time. It is comparatively easy for people to be individual from outside. Kinds of clothes ,various adornments(装饰品), colorful dyed(染)hair. The fashion is changing everyday and it is hard to find two men dressed identically(相同). However, to behave individuality is another story. It means making your own decision, being confident of what you believe in, following no trends but trying to do what you think is right, and speaking out what is in your own mind but not what you hear from other. Something among these is your privacy. We are living in the time when personal choices are always thought highly of. Don’t hesitate when you want to express yourself in word or in action, for it is a good way to show your existence (存在)and stand out from the crowd. At the same time, we should protect our privacy.

相关主题