亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

android task與back stack 開發(fā)文檔翻譯 - 2

系統(tǒng) 2264 0

由于本人英文能力實(shí)在有限,不足之初敬請(qǐng)諒解

本博客只要沒有注明“轉(zhuǎn)”,那么均為原創(chuàng),轉(zhuǎn)貼請(qǐng)注明鏈接

android task與back stack 開發(fā)文檔翻譯 - 1

android task與back stack 開發(fā)文檔翻譯 - 2

android task與back stack 開發(fā)文檔翻譯 - 3

?

Managing Tasks

管理task

?

The way Android manages tasks and the back stack, as described above—by placing all activities started in succession in the same task and in a "last in, first out" stack—works great for most applications and you shouldn't have to worry about how your activities are associated with tasks or how they exist in the back stack.?

However, you might decide that you want to interrupt the normal behavior.?

Perhaps you want an activity in your application to begin a new task when it is started (instead of being placed within the current task); or, when you start an activity, you want to bring forward an existing instance of it (instead of creating a new instance on top of the back stack); or, you want your back stack to be cleared of all activities except for the root activity when the user leaves the task.

android管理task和back stack的方式,像上面描述的那樣-通過在相同的task中連續(xù)的放置打開的activity并且用一個(gè)“后進(jìn)先出”的stack,為大多數(shù)應(yīng)用很好的工作,你沒必要擔(dān)心如何將你的activity與task關(guān)聯(lián)或者他們?nèi)绾未嬖谟赽ack stack中。

也許你想要你應(yīng)用中的一個(gè)activity被打開時(shí)開始一個(gè)新的task(代替放在當(dāng)前的task中);或者當(dāng)你打開一個(gè)activity時(shí),你想把之前已經(jīng)存在的此activity實(shí)例帶到前臺(tái)(代替在back stack頂部新建一個(gè)實(shí)例);或者當(dāng)用戶離開這個(gè)task時(shí),除了根activity,你想要清空stack中的所有activity。

?

You can do these things and more, with attributes in the <activity> manifest element and with flags in the intent that you pass to startActivity().

使用在<activity>中的清單元素的屬性和傳遞給startActivity()函數(shù)的intent中的標(biāo)志,你可以做到上面那些并且可以做的更多

?

In this regard, the the principal <activity> attributes you can use are:

在這方面,你可以使用的主要的<activity>屬性有:

taskAffinity

launchMode

allowTaskReparenting

clearTaskOnLaunch

alwaysRetainTaskState

finishOnTaskLaunch

?

And the principal intent flags you can use are:

你可以使用的主要的intent標(biāo)志有:

FLAG_ACTIVITY_NEW_TASK

FLAG_ACTIVITY_CLEAR_TOP

FLAG_ACTIVITY_SINGLE_TOP

?

In the following sections, you'll see how you can use these manifest attributes and intent flags to define how activities are associated with tasks and how the behave in the back stack.

下面的章節(jié)中,你會(huì)看到如何使用這些清單屬性和intent標(biāo)志來(lái)定義如何把a(bǔ)ctivity與task關(guān)聯(lián)和back stack如何表現(xiàn)。

?

?

Defining launch modes

定義啟動(dòng)模式

Launch modes allow you to define how a new instance of an activity is associated with the current task. You can define different launch modes in two ways:

啟動(dòng)模式允許你定義如何實(shí)例化一個(gè)與當(dāng)前task關(guān)聯(lián)的activity

你可以通過兩種方式定義不同的啟動(dòng)模式

?

Using the manifest file

1使用manifest文件

When you declare an activity in your manifest file, you can specify how the activity should associate with tasks when it starts.

當(dāng)你在你的manifest文件中定義一個(gè)activity時(shí),你可以指定當(dāng)這個(gè)activity打開時(shí),它應(yīng)該如何與task關(guān)聯(lián)。

?

Using Intent flags

2使用intent標(biāo)志

When you call startActivity(), you can include a flag in the Intent that declares how (or whether) the new activity should associate with the current task.

As such, if Activity A starts Activity B, Activity B can define in its manifest how it should associate with the current task (if at all) and Activity A can also request how Activity B should associate with current task.?

If both activities define how Activity B should associate with a task, then Activity A's request (as defined in the intent) is honored over Activity B's request (as defined in its manifest).

當(dāng)你調(diào)用startActivity()時(shí),你可以在intent中包含一個(gè)標(biāo)志來(lái)聲明:新activity應(yīng)該如何(或者是否)與當(dāng)前的task關(guān)聯(lián)

如上所述,如果Activity A開啟Activity B,Activity B可以在它的manifest中定義應(yīng)當(dāng)如何與當(dāng)前的task關(guān)聯(lián),Activity A也可以請(qǐng)求Activity B應(yīng)該如何與當(dāng)前的task關(guān)聯(lián)

如果兩個(gè)activity都定義了Activity B應(yīng)該如何與一個(gè)task關(guān)聯(lián),那么Activity A的請(qǐng)求(如它在intent中定義的)在Activity B的請(qǐng)求(如它在manifest中定義的)之上被接受。

?

Note: Some launch modes available for the manifest file are not available as flags for an intent and, likewise, some launch modes available as flags for an intent cannot be defined in the manifest.

注意:一些啟動(dòng)模式對(duì)于manifest文件可用但是對(duì)于intent的標(biāo)志不可用,并且,同樣地,一些啟動(dòng)模式對(duì)intent的標(biāo)志可用但是不可定義在manifest中。

?

?

Using the manifest file

使用manifest文件

When declaring an activity in your manifest file, you can specify how the activity should associate with a task using the <activity> element's launchMode attribute.

當(dāng)你在manifest文件中定義了一個(gè)activity,你可用使用<activity>元素的launchMode屬性指定這個(gè)activity應(yīng)該如何與task關(guān)聯(lián)

?

The launchMode attribute specifies an instruction on how the activity should be launched into a task.?

There are four different launch modes you can assign to the launchMode attribute:

launchMode屬性指定了一個(gè)此activity應(yīng)該如何進(jìn)入task中的一個(gè)指令

?

"standard" (the default mode)

Default. The system creates a new instance of the activity in the task from which it was started and routes the intent to it.?

The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances.

standard(默認(rèn)模式)

系統(tǒng)在task從開啟它的activity建立了一個(gè)新的activity然后按路線發(fā)送intent到它。

activity可以被實(shí)例化多次,每一個(gè)實(shí)例可以屬于不同的task,一個(gè)task可以有多個(gè)相同的activity實(shí)例。

?

"singleTop"
??? If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
??? The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances (but only if the the activity at the top of the back stack is not an existing instance of the activity).
如果一個(gè)activity實(shí)例已經(jīng)存在于當(dāng)前task的頂部,系統(tǒng)會(huì)通過調(diào)用這個(gè)實(shí)例的onNewIntent()方法將intent送達(dá)到這個(gè)實(shí)例,而不是新建一個(gè)此activity實(shí)例。
這個(gè)activity可以被實(shí)例化多次,每個(gè)實(shí)例可以屬于不同的task,并且一個(gè)task可以擁有多個(gè)此activity實(shí)例(但是必須是在這個(gè)back stack頂部的activity并不是前面所述的activity的一個(gè)已經(jīng)存在的實(shí)例)。


??? For example, suppose a task's back stack consists of root activity A with activities B, C, and D on top (the stack is A-B-C-D; D is on top).
??? An intent arrives for an activity of type D.
??? If D has the default "standard" launch mode, a new instance of the class is launched and the stack becomes A-B-C-D-D.
??? However, if D's launch mode is "singleTop", the existing instance of D receives the intent through onNewIntent(), because it's at the top of the stack—the stack remains A-B-C-D.
??? However, if an intent arrives for an activity of type B, then a new instance of B is added to the stack, even if its launch mode is "singleTop".
例如:假設(shè)一個(gè)task的back stack由A、B、C、D四個(gè)activity組成,其中A為根activity,順序?yàn)锳、B、C、D
一個(gè)請(qǐng)求類型D的intent到達(dá)。
如果D使用的是標(biāo)準(zhǔn)啟動(dòng)模式,一個(gè)新的D實(shí)例會(huì)被啟動(dòng),stack變?yōu)锳-B-C-D-D。
然而,如果D的啟動(dòng)模式為singleTop,那么已經(jīng)存在的D的實(shí)例通過onNewIntent()收到這個(gè)intent,這是因?yàn)樗趕tack的頂端,stack保持著A-B-C-D的順序
如果一個(gè)請(qǐng)求類型B的activity的intent發(fā)出,那么一個(gè)B的新實(shí)例會(huì)被添加到stack,即使B的啟動(dòng)模式為singleTop也一樣。

??? Note: When a new instance of an activity is created, the user can press the Back button to return to the previous activity.
??? But when an existing instance of an activity handles a new intent, the user cannot press the Back button to return to the state of the activity before the new intent arrived in onNewIntent().
注意:當(dāng)一個(gè)activity的時(shí)候被建立,用戶可以按back鍵返回到上一個(gè)activity。
但是當(dāng)一個(gè)已經(jīng)存在的activity處理一個(gè)新intent時(shí),用戶不可能按back鍵回到intent到達(dá)activity的onNewIntent()之前的狀態(tài)。

"singleTask"
??? The system creates a new task and instantiates the activity at the root of the new task.
??? However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance.
??? Only one instance of the activity can exist at a time.
系統(tǒng)建一個(gè)一個(gè)新的task并且實(shí)例化這個(gè)activity作為task的根。
然而,一個(gè)activity的實(shí)例已經(jīng)存在于一個(gè)不同的task中,系統(tǒng)會(huì)通過調(diào)用已經(jīng)存在的實(shí)例的onNewIntent()方法將intent送達(dá)到這個(gè)實(shí)例,而不是新建一個(gè)此activity實(shí)例。
只有一個(gè)這個(gè)activity的實(shí)例可以同時(shí)存在

??? Note: Although the activity starts in a new task, the Back button still returns the user to the previous activity.
雖然這個(gè)activity開啟了一個(gè)新的task,但是back鍵仍然會(huì)是用戶返回到上一個(gè)activity

"singleInstance"

??? Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance.
??? The activity is always the single and only member of its task; any activities started by this one open in a separate task.
除了系統(tǒng)不啟動(dòng)任何其他activity到持有其實(shí)例的task中,其余同singleTask一樣
activity總是單一的并且是它task的唯一成員;任何被他打開dactivity都會(huì)在不同的task中。

As another example, the Android Browser application declares that the web browser activity should always open in its own task—by specifying the singleTask launch mode in the <activity> element.
This means that if your application issues an intent to open the Android Browser, its activity is not placed in the same task as your application.
Instead, either a new task starts for the Browser or, if the Browser already has a task running in the background, that task is brought forward to handle the new intent.
另一個(gè)例子中,Android瀏覽器應(yīng)用聲明web瀏覽器aicivity應(yīng)該在<activity>元素中通過指定singleTask啟動(dòng)模式,打開到其自己的task中。
這意味著:如果你的應(yīng)用發(fā)出一個(gè)intent來(lái)打開Android瀏覽器,瀏覽器的activity不會(huì)作為你的應(yīng)用被放置到相同的task中。

Regardless of whether an activity starts in a new task or in the same task as the activity that started it, the Back button always takes the user to the previous activity.
However, if you start an activity that specifies the singleTask launch mode, then if an instance of that activity exists in a background task, that whole task is brought to the foreground.
At this point, the back stack now includes all activities from the task brought forward, at the top of the stack.
Figure 4 illustrates this type of scenario.

不論是否activity開啟在一個(gè)新task中,或者和開啟它的activity在相同的task中,back鍵總是把用戶帶到上一個(gè)activity。
如果你打開一個(gè)指定了singleTask啟動(dòng)模式的activity,那么如果一個(gè)此activity的實(shí)例存在于后臺(tái)task中,整個(gè)task都會(huì)被帶到前臺(tái)。
這個(gè)時(shí)候,back stack包含了被帶到前臺(tái)的task中所有的activity,放置到stack的頂部。
下圖闡明了這種情況。

android task與back stack 開發(fā)文檔翻譯 - 2

Figure 4.
A representation of how an activity with launch mode "singleTask" is added to the back stack.
If the activity is already a part of a background task with its own back stack, then the entire back stack also comes forward, on top of the current task.
一個(gè)啟動(dòng)模式為singleTask的activity如何添加到back stack的陳述。
如果這個(gè)activity已經(jīng)是后臺(tái)task的一部分,那么他的整個(gè)back stack也會(huì)來(lái)到前臺(tái),在當(dāng)前task的頂部。

Note: The behaviors that you specify for your activity with the launchMode attribute can be overridden by flags included with the intent that start your activity, as discussed in the next section.
注意:你為你的activity通過屬性指定的啟動(dòng)模式可以通過啟動(dòng)你activity的intent中的標(biāo)志被覆寫,就想下面所討論的。

?

?

Using Intent flags
使用Intent的標(biāo)志

When starting an activity, you can modify the default association of an activity to its task by including flags in the intent that you deliver to startActivity().
The flags you can use to modify the default behavior are:
當(dāng)開啟一個(gè)activity,你可以通過在傳給startActivity()函數(shù)中的intent中包含flags來(lái)修改activity與它的task的默認(rèn)關(guān)聯(lián)
你可以使用flags來(lái)修改的默認(rèn)行為有:


FLAG_ACTIVITY_NEW_TASK
??? Start the activity in a new task.
??? If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent().
在新的task中打開一個(gè)activity
如果你正在打開的activity已經(jīng)運(yùn)行在一個(gè)task中,那個(gè)task會(huì)被帶到前臺(tái)恢復(fù)到它最近的狀態(tài)并且這個(gè)activity會(huì)在onNewIntent()收到這個(gè)新的intent

??? This produces the same behavior as the "singleTask" launchMode value, discussed in the previous section.
這會(huì)導(dǎo)致與singleTask啟動(dòng)模式相同的行為,像上面討論的。

FLAG_ACTIVITY_SINGLE_TOP
??? If the activity being started is the current activity (at the top of the back stack), then the existing instance receives a call to onNewIntent(), instead of creating a new instance of the activity.
如果這個(gè)activity被打開在當(dāng)前activity(在back stack頂部),那么已經(jīng)存在的實(shí)例的onNewIntent()會(huì)被調(diào)用,代替新建一個(gè)此activity的實(shí)例。

??? This produces the same behavior as the "singleTop" launchMode value, discussed in the previous section.
這會(huì)導(dǎo)致與singleTop啟動(dòng)模式相同的行為,像上面討論的。

FLAG_ACTIVITY_CLEAR_TOP
??? If the activity being started is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it are destroyed and this intent is delivered to the resumed instance of the activity (now on top), through onNewIntent()).
如果要打開的activity已經(jīng)運(yùn)行在當(dāng)前task中,那么不再啟動(dòng)此activty一個(gè)新實(shí)例,取而代之,所有在此activity上的其他 activity會(huì)被銷毀,并且這個(gè)intent通過onNewIntent()會(huì)發(fā)送到恢復(fù)的此activity中(現(xiàn)在在最task上面)

??? There is no value for the launchMode attribute that produces this behavior.
沒有啟動(dòng)模式屬性會(huì)導(dǎo)致此行為


??? FLAG_ACTIVITY_CLEAR_TOP is most often used in conjunction with FLAG_ACTIVITY_NEW_TASK.
FLAG_ACTIVITY_CLEAR_TOP最常用的用法是與FLAG_ACTIVITY_NEW_TASK結(jié)合

??? When used together, these flags are a way of locating an existing activity in another task and putting it in a position where it can respond to the intent.
一起使用時(shí),這些標(biāo)識(shí)是定位一個(gè)已經(jīng)在另一個(gè)task中存在的activity的一種方式,并且放置到一個(gè)可以回應(yīng)此intent的位置


??? Note: If the launch mode of the designated activity is "standard", it too is removed from the stack and a new instance is launched in its place to handle the incoming intent.
??? That's because a new instance is always created for a new intent when the launch mode is "standard".
注意:如果activity指定啟動(dòng)模式的是standard,它也會(huì)被從stack中移除,并且一個(gè)新的實(shí)例被啟動(dòng)來(lái)處理到來(lái)的intent
那是因?yàn)槿绻麊?dòng)模式是standard,一個(gè)新的intent總是會(huì)創(chuàng)建一個(gè)新的實(shí)例。

?

?

本文來(lái)自對(duì)下面地址的翻譯,英文水平實(shí)在有限,希望拍磚同時(shí)能給予指正。

http://developer.android.com/guide/components/tasks-and-back-stack.html

?

?

?

轉(zhuǎn)貼請(qǐng)保留以下鏈接

本人blog地址

http://su1216.iteye.com/

http://blog.csdn.net/su1216/

android task與back stack 開發(fā)文檔翻譯 - 2


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 成年女人免费看片 | 久久亚洲精品玖玖玖玖 | 日本一区二区三区高清福利视频 | 亚洲高清日韩精品第一区 | 成人动漫影院 | 97精品国产综合久久久久久欧美 | 国产成人在线视频网站 | 伊人网久久网 | 日韩欧美精品综合一区二区三区 | 国产欧美一区二区精品久久久 | 99精品免费视频 | 久久久久久国产精品免费免费 | 韩国美女高清爽快一级毛片 | a视频在线播放 | 性欧美4k高清精品 | 玖热在线| 亚洲 欧洲 自拍 另类 校园 | 久久青草免费91线频观看不卡 | 国产午夜精品福利视频 | 69做爰视频在线观看 | 亚洲视频一区二区 | 99久久日本一区二区波多野结衣 | 成人美女隐私免费 | 亚洲精品久久久久久小说 | 精品72久久久久久久中文字幕 | 国产精品国偷自产在线 | 亚洲国产精品成人综合久久久 | 国产精品久久久久蜜芽 | 久久久久综合网久久 | 国产a级一级久久毛片 | 第一国内永久免费福利视频 | 亚洲欧美在线播放 | 久久久亚洲欧洲日产国码二区 | 日韩1区| 中文在线观看视频 | 久久精品免视看国产明星 | 香蕉免费一区二区三区在线观看 | 亚洲综合一区二区三区 | 久久一区二区三区不卡 | 天天草天天干 | 一级毛片高清免费播放 |