/install android-stack-analyzer
Android Stack Analyzer - 安卓页面栈分析工具
简介
这个技能让你通过ADB命令快速查看安卓设备的页面栈信息,包括当前页面、Activity历史、Fragment等。适用于Android开发者、测试人员和逆向工程师。
功能特点
- 查看当前最上层页面
- 分析完整Activity页面栈
- 查看Fragment页面栈
- 监控页面切换
- 支持不同Android版本的命令兼容性
使用方法
1. 查看当前最上层页面
Windows:
adb shell "dumpsys window | findstr mCurrentFocus"
Linux/macOS:
adb shell "dumpsys window | grep mCurrentFocus"
输出示例:
mCurrentFocus=Window{... u0 com.example.app/com.example.app.MainActivity}
2. 查看完整Activity页面栈
Windows:
adb shell "dumpsys activity activities | findstr /R "Hist\|ResumedActivity\|mFocusedActivity"
Linux/macOS:
adb shell "dumpsys activity activities | grep -E 'Hist|ResumedActivity|mFocusedActivity'"
输出示例:
* Hist #3: ActivityRecord{... u0 com.example.app/.activity.MainActivity t533}
* Hist #2: ActivityRecord{... u0 com.example.app/.activity.SettingsActivity t533}
ResumedActivity: ActivityRecord{... u0 com.example.app/.activity.MainActivity t533}
3. 查看页面栈中的Fragment
Windows:
adb shell "dumpsys activity \x3C包名>"
示例:查看com.example.app的Fragment信息
adb shell "dumpsys activity com.example.app"
Linux/macOS:
adb shell "dumpsys activity \x3C包名>"
示例:查看com.example.app的Fragment信息
adb shell "dumpsys activity com.example.app"
4. 查看Activity任务栈树形结构
Windows:
adb shell "dumpsys activity activities | findstr /R "TaskRecord\|ActivityRecord"
Linux/macOS:
adb shell "dumpsys activity activities | grep -E 'TaskRecord|ActivityRecord'"
5. 查看最近任务列表
Windows:
adb shell "dumpsys activity recents"
Linux/macOS:
adb shell "dumpsys activity recents"
6. 实时监控当前页面切换
Windows:
adb shell "while /l %%i in () do @echo [%time%] & adb shell "dumpsys window | findstr mCurrentFocus" & timeout /t 1 > nul"
Linux/macOS:
adb shell "while true; do echo "[$(date '+%H:%M:%S')] $(adb shell 'dumpsys window | grep mCurrentFocus')"; sleep 1; done"
7. 查看Activity生命周期状态
Windows:
adb shell "dumpsys activity activities | findstr state="
Linux/macOS:
adb shell "dumpsys activity activities | grep 'state='"
高级用法
查看特定包名的详细Activity信息
Windows:
adb shell "dumpsys activity a \x3C包名>"
Linux/macOS:
adb shell "dumpsys activity a \x3C包名>"
查看所有运行中的进程及对应的Activity
Windows:
adb shell "dumpsys activity processes"
Linux/macOS:
adb shell "dumpsys activity processes"
查看Back Stack详细信息
Windows:
adb shell "dumpsys activity activities | findstr /R "mResumedActivity\|mFocusedActivity"
Linux/macOS:
adb shell "dumpsys activity activities | grep -E 'mResumedActivity|mFocusedActivity'"
输出解析
mCurrentFocus字段
u0- 用户应用(User app)s0- 系统应用(System app)com.example.app- 包名com.example.app.MainActivity- Activity类名
Activity历史栈
* Hist #3- 历史记录中的第3个Activity(数字越大越新)u0- 用户应用t533- 任务IDinHistory=true- 在历史栈中mStartingWindowState=STARTING_WINDOW_NOT_SHOWN- 启动窗口状态
Activity状态
INITIALIZING- 初始化中RESUMED- 前台可见PAUSED- 暂停STOPPED- 停止DESTROYED- 已销毁
兼容性说明
Windows平台
- 使用
adb而不是adb.exe(通常PATH中已配置) - 使用
findstr而不是grep - 使用
findstr /R进行正则匹配 - 命令示例:
adb shell "dumpsys window | findstr mCurrentFocus"
Linux/macOS平台
- 使用
adb命令 - 使用
grep命令 - 支持正则表达式匹配
- 命令示例:
adb shell "dumpsys window | grep mCurrentFocus"
Android版本差异
- Android 13+ 部分
dumpsys输出格式有变化 - 如果命令不生效,可以先查看原始输出确认字段名
- 某些设备可能需要root权限才能获取完整信息
常见问题
1. findstr/grep命令不可用
某些设备上可能没有这些命令,可以:
- 使用
adb shell dumpsys window然后手动查找 - 使用
adb shell dumpsys activity activities然后手动查找
2. 输出太多信息
可以使用包名过滤:
adb shell "dumpsys activity activities | grep com.example.app"
3. 系统应用信息被隐藏
某些设备可能需要开启开发者选项中的"显示系统级应用"
4. 页面栈不准确
- 可能是WebView或Dialog/PopupWindow遮挡
- 可以使用
dumpsys activity activities | grep ResumedActivity确认
实用脚本
自动化脚本示例
#!/bin/bash
# 获取当前页面
echo "=== 当前页面 ==="
adb shell "dumpsys window | grep mCurrentFocus"
# 获取页面栈
echo -e "\
=== 页面栈 ==="
adb shell "dumpsys activity activities | grep -E 'Hist|ResumedActivity'"
# 获取最近任务
echo -e "\
=== 最近任务 ==="
adb shell "dumpsys activity recents"
批量检查多个应用
#!/bin/bash
apps=("com.example.app1" "com.example.app2" "com.example.app3")
for app in "${apps[@]}"; do
echo "=== 检查 $app ==="
adb shell "dumpsys activity activities | grep $app"
echo ""
done
注意事项
- 确保设备已开启USB调试模式
- 某些设备可能需要授权ADB连接
- 系统应用信息可能需要root权限
- 不同Android版本输出格式可能不同
- 部分设备可能禁用了某些dumpsys命令
更新日志
- v1.0.0 - 初始版本,支持基本页面栈分析功能
- v1.1.0 - 添加Fragment查看功能
- v1.2.0 - 添加实时监控功能
- v1.3.0 - 添加跨平台兼容性支持
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install android-stack-analyzer - After installation, invoke the skill by name or use
/android-stack-analyzer - Provide required inputs per the skill's parameter spec and get structured output
What is Android Stack Analyzer?
Quickly view and analyze Android device page stacks including current page, Activity history, Fragments, and monitor page switches via ADB commands. It is an AI Agent Skill for Claude Code / OpenClaw, with 39 downloads so far.
How do I install Android Stack Analyzer?
Run "/install android-stack-analyzer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Android Stack Analyzer free?
Yes, Android Stack Analyzer is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Android Stack Analyzer support?
Android Stack Analyzer is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Android Stack Analyzer?
It is built and maintained by zyq (@githubzyq); the current version is v1.0.0.