Android 如何快速定位当前页面是哪个Activity or Fragment

在日常需求开发中,经常碰到不太熟悉的模块,如何快速定位相应页面对应的Activity/Fragment ?

 

(1)查看当前Activity  :adb shell "dumpsys window w | grep name="

(2)查看当前栈顶的Activity :adb shell dumpsys activity | grep "mFocusedActivity"

(3)查看当前栈顶的Activity的Fragment :adb shell dumpsys activity your.package.name

也可以不用包名,而直接使用"top"选项:adb shell dumpsys activity top

CHUANCUI-MC0:~ chuancui$ adb shell dumpsys --h
usage: dumpsys
         To dump all services.
or:
       dumpsys [-t TIMEOUT] [--help | -l | --skip SERVICES | SERVICE [ARGS]]
         --help: shows this help
         -l: only list services, do not dump them
         -t TIMEOUT: TIMEOUT to use in seconds instead of default 10 seconds
         --skip SERVICES: dumps all services but SERVICES (comma-separated list)
         SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ adb shell dumpsys activity -h
Activity manager dump options:
  [-a] [-c] [-p PACKAGE] [-h] [WHAT] ...
  WHAT may be one of:
    a[ctivities]: activity stack state
    r[recents]: recent activities state
    b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state
    broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics
    i[ntents] [PACKAGE_NAME]: pending intent state
    p[rocesses] [PACKAGE_NAME]: process state
    o[om]: out of memory management
    perm[issions]: URI permission grant state
    prov[iders] [COMP_SPEC ...]: content provider state
    provider [COMP_SPEC]: provider client-side state
    s[ervices] [COMP_SPEC ...]: service state
    as[sociations]: tracked app associations
    settings: currently applied config settings
    service [COMP_SPEC]: service client-side state
    package [PACKAGE_NAME]: all state related to given package
    all: dump all activities
    top: dump the top activity
  WHAT may also be a COMP_SPEC to dump activities.
  COMP_SPEC may be a component name (com.foo/.myApp),
    a partial substring in a component name, a
    hex 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.
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ 
CHUANCUI-MC0:~ chuancui$ adb shell dumpsys activity -p com.companyxxx.appxxx top

 

你可能感兴趣的:(Android)