1 需求
查询当前运行activity adb shell dumpsys activity | findstr mFocusedAppadb shell dumpsys activity | findstr mFocusedWindowadb shell dumpsys activity topadb shell dumpsys window | findstr mCurrentFocus
2 语法
Activity manager dump options:[-a] [-c] [-p PACKAGE] [-h] [WHAT] ...WHAT may be one of:a[ctivities]: activity stack stater[recents]: recent activities stateb[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast statebroadcast-stats [PACKAGE_NAME]: aggregated broadcast statisticsi[ntents] [PACKAGE_NAME]: pending intent statep[rocesses] [PACKAGE_NAME]: process stateo[om]: out of memory managementperm[issions]: URI permission grant stateprov[iders] [COMP_SPEC ...]: content provider stateprovider [COMP_SPEC]: provider client-side states[ervices] [COMP_SPEC ...]: service stateallowed-associations: current package association restrictionsas[sociations]: tracked app associationsexit-info [PACKAGE_NAME]: historical process exit informationlmk: stats on low memory killerlru: raw LRU process listbinder-proxies: stats on binder objects and IPCssettings: currently applied config settingsservice [COMP_SPEC]: service client-side statepackage [PACKAGE_NAME]: all state related to given packageall: dump all activitiestop: dump the top activityWHAT may also be a COMP_SPEC to dump P_SPEC may be a component name (com.foo/.myApp),a partial substring in a component name, ahex object identifier.-a: include all available server state.-c: include client state.-p: limit output to given package.--checkin: output checkin format, resetting data.--C: output checkin format, not resetting data.--proto: output dump in protocol buffer format.--autofill: dump just the autofill-related state of an activity
3.X 示例:获取当前运行activity的名字
adb shell dumpsys activity | findstr mFocusedApp
adb shell dumpsys activity | findstr mFocusedWindow
备注:前面两个命令是锁屏前,后面两个命令是锁屏后
adb shell dumpsys activity activities
adb shell dumpsys window | findstr mCurrentFocus
4 参考资料