前言
好记性不如烂笔头,记录一下日常开发调试过程中通过 adb 命令查看设备 Activity 或者 Window 信息、层级关系的常见方式。
查看当前任务栈中的 Activity
adb shell dumpsys activity activities | grep '* ActivityRecord{'
* ActivityRecord{b7159c8 u0 com.android.launcher/.rust.RustActivity t172}
* ActivityRecord{17619a4 u0 com.android.car.chargemanagement/.ChargeActivity t173}
* ActivityRecord{6ce3186 u0 com.android.launcher3/com.android.window.VirtualLauncher t49}
* ActivityRecord{e4c4c25 u0 com.android.car.weather/.WeatherActivity t154}
* ActivityRecord{d017b58 u0 com.android.car.settings/.common.CarSettingActivities$ApplicationsDetailsActivity t52}
* ActivityRecord{bafd3cf u0 com.android.psglauncher/com.android.passenger.presentation.home.Launcher t47}
* ActivityRecord{1b934e8 u0 com.android.hud/.HudActivity t45}
* ActivityRecord{aa2e358 u0 com.android.newlauncher/com.android.passenger.presentation.home.Launcher t43}
## 查看当前任务栈中的 Activity
通过 `adb shell dumpsys activity activities | grep '* ActivityRecord{'` 命令,可以获取当前任务栈中 Activity 的相关信息。以下是命令输出中各参数的详细解读:
### 参数解析
以 `* ActivityRecord{b7159c8 u0 com.android.launcher/.rust.RustActivity t172}` 为例:
- **b7159c8**
- **含义**:ActivityRecord 的唯一哈希码(内存地址标识),用于系统内部区分不同 Activity 实例。
- **作用**:在调试时定位具体 Activity 的内存对象。
- **u0**
- **含义**:用户 ID(User ID),`0` 表示设备主用户(系统默认用户)。
- **扩展**:在多用户设备中可能显示 `u1`、`u2` 等,表示不同用户的 Activity。
- **t172**
- **含义**:任务栈 ID(Task ID),标识 Activity 所属的任务栈。
- **规则**:
- 系统应用任务栈 ID 较小(如 `t172`、`t173`)。
- 用户应用任务栈 ID 较大(如 `t49`、`t52`)。
- **关联信息**:通过 `dumpsys activity tasks` 可查看任务栈详细信息。
查看当前栈顶 Activity
adb shell dumpsys activity | grep "mFocused"
mFocusedApp=ActivityRecord{b7159c8 u0 com.android.launcher/.rust.RustActivity t172}
mFocusedWindow=Window{c1eceed u0 mDisplayId 0 pkgName com.android.launcher com.android.launcher/com.android.launcher.rust.RustActivity}
mFocusedApp=ActivityRecord{bafd3cf u0 com.android.psglauncher/com.android.passenger.presentation.home.Launcher t47}
mFocusedApp=null
mFocusedWindow=Window{950f929 u0 mDisplayId 2 pkgName com.android.hud com.android.hud/com.android.hud.HudActivity}
mFocusedApp=null
mFocusedApp=null
查看焦点窗口
adb shell dumpsys window | grep -E "mCurrentFocus|mFocusedApp"
mCurrentFocus=null
mCurrentFocus=null
mCurrentFocus=Window{950f929 u0 mDisplayId 2 pkgName com.android.hud com.android.hud/com.android.hud.HudActivity}
mCurrentFocus=null
mCurrentFocus=Window{c1eceed u0 mDisplayId 0 pkgName com.android.launcher com.android.launcher/com.android.launcher.rust.RustActivity}
查看所有Activity任务栈(精简版)
adb shell dumpsys activity activities | grep "Hist"
查看特定Activity的详细信息(需知道包名和类名)
adb shell dumpsys activity com.example.package/.MainActivity
TASK 10083:com.android.car.weather id=154 userId=0
ACTIVITY com.android.car.weather/.WeatherActivity e4c4c25 pid=11275
Local Activity f673026 State:
mResumed=true mStopped=false mFinished=false
mIsInMultiWindowMode=false mIsInPictureInPictureMode=false
mChangingConfigurations=false
mCurrentConfig={1.0 460mcc9mnc [zh_CN] ldltr sw1620dp w2880dp h1360dp 160dpi xlrg long hdr land car finger qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 2880, 1620) mAppBounds=Rect(0, 0 - 2880, 1440) mMaxBounds=Rect(0, 0 - 2880, 1620) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} as.4 s.2 fontWeightAdjustment=0}
mLoadersStarted=true
Active Fragments in 29e584f:
#0: ReportFragment{86ddbdc #0 androidx.lifecycle.LifecycleDispatcher.report_fragment_tag}
mFragmentId=#0 mContainerId=#0 mTag=androidx.lifecycle.LifecycleDispatcher.report_fragment_tag
mState=5 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
mAdded=true mRemoving=false mFromLayout=false mInLayout=false
mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
mRetainInstance=false mRetaining=false mUserVisibleHint=true
mFragmentManager=FragmentManager{29e584f in HostCallbacks{7ebd4e5}}
mHost=android.app.Activity$HostCallbacks@7ebd4e5
Child FragmentManager{8659bba in ReportFragment{86ddbdc}}:
FragmentManager misc state:
mHost=android.app.Activity$HostCallbacks@7ebd4e5
mContainer=android.app.Fragment$1@4922a6b
mParent=ReportFragment{86ddbdc #0 androidx.lifecycle.LifecycleDispatcher.report_fragment_tag}
mCurState=5 mStateSaved=false mDestroyed=false
Added Fragments:
#0: ReportFragment{86ddbdc #0 androidx.lifecycle.LifecycleDispatcher.report_fragment_tag}
FragmentManager misc state:
mHost=android.app.Activity$HostCallbacks@7ebd4e5
mContainer=android.app.Activity$HostCallbacks@7ebd4e5
mCurState=5 mStateSaved=false mDestroyed=false
、、、
1.屏幕参数
- sw1620dp:最小宽度为 1620dp。
- w2880dp h1360dp:物理分辨率(可能为横屏模式)
- 160dpi:屏幕密度,影响文字和图标缩放。
2.窗口边界与手势区域
InsetsState
mDisplayFrame=Rect(0, 0 - 2880, 1620)
InsetsSource type=ITYPE_STATUS_BAR frame=[0,0][2880,80] visible=true
InsetsSource type=ITYPE_NAVIGATION_BAR frame=[0,1440][2880,1620] visible=true
InsetsSource type=ITYPE_LEFT_GESTURES frame=[0,0][0,1620] visible=true
InsetsSource type=ITYPE_RIGHT_GESTURES frame=[2880,0][2880,1620] visible=true
- 状态栏与导航栏:高度分别为 80px 和 180px(1620-1440),位于屏幕顶部和底部。
- 屏幕最左侧垂直区域(0,0~0,1620)
- 屏幕最右侧垂直区域(2880,0~2880,1620)
查看当前所有窗口信息
adb shell dumpsys window windows
输出非常多
本文由mdnice多平台发布