1. 程式人生 > >android--Manifest檔案中allowTaskReparenting屬性的含義

android--Manifest檔案中allowTaskReparenting屬性的含義

allowTaskReparenting的官方定義是“Whether or not the activity can move from the task that started it to the task it has an affinity for when that task is next brought to the front — "true" if it can move, and "false" if it must remain with the task where it started.”簡單翻譯就是是否允許該Activity從啟動他的任務(可以理解為activity棧)轉移到與他有親密關係(affinity)的任務中,當有親密關係的任務再次啟動時。幹看這句話我是沒懂什麼意思,後來看到一個帖子的解釋,稍微明白了一點。就用官方提供的那個例子來說,一個郵件應用,當收到的郵件內容中包含一個連結地址時,使用者點選這個連結會呼叫browser應用的一個activityB去顯示。但是下次browser應用再顯示時,這個activityB還存在,而下次再顯示郵件應用時,activityB就不在其中了。是因為browser和activityB有相同的affinity,所以從郵件應用的任務中(這裡要解釋一下,如果是系統的browser APP,那麼顯示網頁內容的activityB將分配一個新的任務棧,因為他配置launchmode是singletask)轉回到了browser應用的任務中去。如果activityB的allowTaskReparenting
屬性設定為false,那麼當browser啟動時,它就不會回到browser的任務中,而是一直呆在郵件應用的任務中。