自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
WindowManager
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
WindowManager 轉儲作業會提供 WindowManager 在特定時間點的快照。WindowManager 追蹤記錄會以時間順序顯示狀態,提供寶貴的深入分析結果,協助您瞭解為何視窗會顯示在螢幕上、其設定,或其活動、工作、顯示畫面或 WindowManager 階層中的任何其他元素。這項資訊對於排解問題非常實用,例如「為什麼我的應用程式無法顯示」或「我在切換應用程式時看到畫面閃爍」。
Winscope 的 WindowManager 檢視器會針對追蹤記錄和傾印顯示這項資訊。
如要進一步瞭解追蹤記錄收集作業,請參閱 WindowManager。
圖 1. WindowManager 追蹤分析。
畫面左側會顯示窗戶的 3D 檢視畫面。矩形檢視畫面會考量視窗邊界、z 順序和透明度。
分頁的中央區塊會顯示視窗階層。除了視窗、活動和工作之間的父子關係外,這個檢視畫面還包含下列資訊:
畫面右側顯示所有可用屬性的 proto 傾印。如要進一步瞭解 Proto 傾印區段的功能,請參閱「屬性」。
@IntDef 翻譯
@IntDef
轉譯是 WindowManager 屬性面板的重要屬性。@IntDef
表示整數類型的註解元素代表邏輯類型,且其值必須是明確命名的常數之一。@IntDef
會在 Android 程式碼庫中使用,而非枚舉,以減輕對記憶體和效能的影響。
以下是 @IntDef 用法的範例:
/**
* The modes to control how root task is moved to the front when calling {@link Task#reparent}.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({
REPARENT_MOVE_ROOT_TASK_TO_FRONT,
REPARENT_KEEP_ROOT_TASK_AT_FRONT,
REPARENT_LEAVE_ROOT_TASK_IN_PLACE
})
@interface ReparentMoveRootTaskMode {}
// Moves the root task to the front if it was not at the front
static final int REPARENT_MOVE_ROOT_TASK_TO_FRONT = 0;
// Only moves the root task to the front if it was focused or frontmost already
static final int REPARENT_KEEP_ROOT_TASK_AT_FRONT = 1;
// Do not move the root task as a part of reparenting
static final int REPARENT_LEAVE_ROOT_TASK_IN_PLACE = 2;
標記會儲存為整數,而非使用人類可讀的值,這可能很難解讀。Winscope 會使用 @IntDef
定義,將這些旗標轉譯為人類可讀的值。在編譯期間,Winscope 會收集 @IntDef
值的字典,並在執行階段使用這份清單將 @IntDef
例項解碼為人類可讀的格式。舉例來說,如果活動的 activityType
為 2
,就會轉譯為 ACTIVITY_TYPE_HOME
的 activityType
。同樣地,如果視窗含有 flags=2173763840
,Winscope 會將其翻譯為:
flags=FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | FLAG_HARDWARE_ACCELERATED |
FLAG_SPLIT_TOUCH | FLAG_SHOW_WALLPAPER | FLAG_LAYOUT_INSET_DECOR |
FLAG_LAYOUT_IN_SCREEN
如果 Winscope 無法正確轉譯 @IntDef
例項,請按照「更新 @IntDef 對應」中的步驟,更新 Winscope 已知的 @IntDef
例項清單。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# WindowManager\n\n[WindowManager](/docs/core/graphics/surfaceflinger-windowmanager#windowmanager)\ndumps provide a snapshot of WindowManager at a specific time. WindowManager\ntraces feature a chronological sequence of states that provide valuable insights\ninto why a window appears on screen, its configuration, or that of its activity,\ntask, display or of any other element in the WindowManager hierarchy. This\ninformation is useful for troubleshooting issues like *why isn't my app\nvisible* or *I experienced flickering while changing between apps*.\n\nWinscope's WindowManager viewer displays this information for both traces\nand dumps.\n\nSee\n[WindowManager](/docs/core/graphics/winscope/capture/adb#capture-adb-wm)\nfor more information about trace collection.\n\n**Figure 1.** WindowManager trace analysis.\n\nThe left side of the screen features a 3D view of the windows. The rects view\nconsiders window bounds, z-order, and opacity.\n\nThe tab's central segment shows the window hierarchy. In addition to the\nparent-child relationships between windows, activities, and tasks, this view\nalso includes the following information:\n\n- **V:** Identifies visible windows.\n\nThe right side of the screen features a **proto dump** of all available\nproperties. For more information about the features of the proto dump section\nsee [Properties](/docs/core/graphics/winscope/analyze/overview#analyze-properties).\n\n@IntDef translation\n-------------------\n\n`@IntDef` translation is a key property of the WindowManager properties panel.\n`@IntDef` denotes that the annotated element of integer type represents a\nlogical type and that its value must be one of the explicitly named constants.\n`@IntDef` is used within the Android codebase instead of enums for mitigating\nmemory and performance impact.\n\nThe following is an example of @IntDef usage: \n\n /**\n * The modes to control how root task is moved to the front when calling {@link Task#reparent}.\n */\n @Retention(RetentionPolicy.SOURCE)\n @IntDef({\n REPARENT_MOVE_ROOT_TASK_TO_FRONT,\n REPARENT_KEEP_ROOT_TASK_AT_FRONT,\n REPARENT_LEAVE_ROOT_TASK_IN_PLACE\n })\n @interface ReparentMoveRootTaskMode {}\n\n // Moves the root task to the front if it was not at the front\n static final int REPARENT_MOVE_ROOT_TASK_TO_FRONT = 0;\n // Only moves the root task to the front if it was focused or frontmost already\n static final int REPARENT_KEEP_ROOT_TASK_AT_FRONT = 1;\n // Do not move the root task as a part of reparenting\n static final int REPARENT_LEAVE_ROOT_TASK_IN_PLACE = 2;\n\nFlags are stored as *integers* , instead of using\nhuman-readable values, which can be challenging to interpret. Winscope\ntranslates these flags into human-readable values using `@IntDef` definitions.\nDuring compilations, Winscope collects a dictionary of `@IntDef` values and uses\nthis list to decode `@IntDef` instances into a human-readable format at\nruntime. For example, an activity with `activityType` of `2` is translated into\n`activityType` of `ACTIVITY_TYPE_HOME`. Similarly, a window with\n`flags=2173763840` is translated in Winscope as:\n\n`flags=FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | FLAG_HARDWARE_ACCELERATED |\nFLAG_SPLIT_TOUCH | FLAG_SHOW_WALLPAPER | FLAG_LAYOUT_INSET_DECOR |\nFLAG_LAYOUT_IN_SCREEN`\n\nIf Winscope doesn't translate an `@IntDef` instance correctly,\nfollow the steps in [Update @IntDef mapping](/docs/core/graphics/winscope/run#update-intdef)\nto update the list of `@IntDef` instances known by Winscope."]]