android:launchMode概述

來源:互聯網
上載者:User

標籤:

android:launchModeAn instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:"standard" "singleTop" "singleTask" "singleInstance"The default mode is "standard".

Activity有四種啟動模式,預設為標準型。還是先給出表格,看的更加清楚。

Use Cases Launch Mode Multiple Instances? Comments
Normal launches for most activities  "standard" Yes Default. The system always creates a new instance of the activity in the target task and routes the intent to it.
"singleTop" Conditionally If an instance of the activity already exists at the top of the target 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.
Specialized launches (not recommended for general use)  "singleTask" No The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.
"singleInstance" No 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.

 "standard"可以有多個相同執行個體,並且每次啟動一個Activity,系統總是在任務棧中建立一個Activity新的執行個體並且為它設定意圖的路徑。

"singleTop"的多個執行個體是有條件的,如果一個Activity的執行個體已經存在與任務棧頂端,系統通過調用它的onNewIntent()函數來為意圖設定到此執行個體的路徑而非建立一個新的相同執行個體。

以上兩個是常用的。

後兩個不常用。

"singleTask"只有一個執行個體。在當前任務棧中,如果執行個體不存在,則會建立一個,如果這個Activity的執行個體已經存在,系統通過調用它的onNewIntent()函數來為意圖設定到此執行個體的路徑而非建立一個新的執行個體,即會結束它上面全部的Activity。如果另一個程式啟動了這個Activity,並且此Activity已經在當前任務棧中建立,則不會在那個任務棧建立執行個體,而是使用引用指向當前任務棧中的執行個體。

例如:

B為singleTask模式

操作:A->B          A->B->C          A->B->C->B            A->B->C->B->C->A             A->B->C->B->C->A->B
實際:A->B          A->B->C          A->B                              A->B->C->A                               A->B

 

"singleInstance"Activity總是獨佔一個任務棧。如果A中啟動B,系統為B另外開闢一個任務棧。

 

android:launchMode概述

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.