1

查看当前界面Activity:

adb shell "dumpsys activity top | grep ACTIVITY | tail -n 1"
  • dumpsys activity top :打印顶层Activity信息
  • grep ACTIVITY:从上个命令结果中过滤出Activity相关信息
  • tail -n 1:从上一步过滤结果中继续过滤出最后一条记录,也就是当前界面(顶层top)activity

命令执行结果:

PS C:\Users\Administrator> adb shell "dumpsys activity top | grep ACTIVITY | tail -n 1"
  ACTIVITY com.android.settings/.SubSettings 4726cca pid=8079

查看当前界面Fragment:

adb shell "dumpsys activity top | grep '#[0-9]: ' | tail -n 1"

命令执行结果:

PS C:\Users\Administrator> adb shell "dumpsys activity top | grep '#[0-9]: ' | tail -n 1"
        #0: DevelopmentSettingsDashboardFragment{d1b926e #1 id=0x7f0a03e2}

查看Activity任务栈(仅适用android11以及以上):

adb shell "dumpsys activity activities | grep '* ActivityRecord{'"

windows下可以将下面代码保存成bat文件直接运行:

@echo off &PUSHD %~DP0 &TITLE Settings Tool

:menu
cls
echo Notes: Please connect device with adb, it's only adapter for Android 11.
echo === Menu ===
echo [1] view top activity
echo [2] view top fragment
echo [3] view activity stack
echo ============
set /p user_input=Please choose menu:
if %user_input%==1 goto topActivity
if %user_input%==2 goto topFragment
if %user_input%==3 goto activityStack
if not %user_input%=="" goto menu

:topActivity
adb wait-for-device
adb shell "dumpsys activity top | grep ACTIVITY | tail -n 1"
echo. & pause
goto menu

:topFragment
adb wait-for-device
adb shell "dumpsys activity top | grep '#[0-9]: ' | tail -n 1"
echo. & pause
goto menu

:activityStack
adb wait-for-device
adb shell "dumpsys activity activities | grep '* ActivityRecord{'"
echo. & pause
goto menu

运行结果:

Notes: Please connect device with adb, it's only adapter for Android 11.
=== Menu ===
[1] view top activity
[2] view top fragment
[3] view activity stack
============
Please choose menu:2
        #0: AppCategorySelectFragment{4c31805 #0 id=0x7f0a004e}

请按任意键继续. . .

嘿嘿哟哟
12 声望3 粉丝