首页 > 代码库 > Android使用adb获得activity堆栈信息

Android使用adb获得activity堆栈信息

非常有用的命令:

adb shell dumpsys activity

该命令可以看到当前运行的是哪个activity,运行的一些进程等

首先可以看到运行的进程:

ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
  Process LRU list (sorted by oom_adj, 43 total, non-act at 1, non-svc at 1):
    PERS #42: sys   F/ /P  trm: 0 804:system/1000 (fixed)
    PERS #41: pers  F/ /P  trm: 0 914:com.android.keyguard/u0a8 (fixed)
    PERS #40: pers  F/ /P  trm: 0 960:com.android.systemui/u0a8 (fixed)
    PERS #39: pers  F/ /P  trm: 0 1133:com.android.phone/1001 (fixed)
    PERS #38: pers  F/ /P  trm: 0 1146:com.mediatek.voicecommand/u0a77 (fixed)
    PERS #37: pers  F/ /P  trm: 0 1159:com.huaqin.msa/1000 (fixed)
    PERS #36: pers  F/ /P  trm: 0 1173:com.cooee.widget.samweatherclock/u0a79 (fixed)
    PERS #35: pers  F/ /P  trm: 0 1188:com.mediatek.bluetooth/1002 (fixed)
    PERS #34: pers  F/ /P  trm: 0 1201:com.mediatek.voiceextension/1000 (fixed)
    PERS #33: pers  F/ /P  trm: 0 1216:com.coco.lock2.local.app.cyclelibgdx/u0a45 (fixed)
    PERS #32: pers  F/ /P  trm: 0 1229:com.cooee.uni.allwidget/u0a73 (fixed)
    PERS #31: pers  F/ /P  trm: 0 1244:com.coco.lock2.local.app.valentine/u0a74 (fixed)
    Proc #30: fore  F/A/T  trm: 0 1257:com.cooee.unilauncher.desktop/u0a2 (top-activity)
    Proc # 7: vis   F/ /IF trm: 0 1350:android.process.media/u0a6 (provider)
        com.android.providers.media/.MediaProvider<=Proc{1530:com.android.music/u0a55}
    Proc # 0: vis   F/ /IF trm: 0 1530:com.android.music/u0a55 (service)
        com.android.music/.MediaPlaybackService<=Proc{1257:com.cooee.unilauncher.desktop/u0a2}
    Proc #29: prcp  F/ /IF trm: 0 1090:com.iflytek.inputmethod/u0a83 (service)
        com.iflytek.inputmethod/.FlyIME<=Proc{804:system/1000}
    Proc #14: prcp  F/S/IF trm: 0 1599:com.mediatek.mtklogger/u0a54 (fg-service)
    Proc #25: svc   B/ /S  trm: 0 2514:com.android.system/1000 (started-services)
    Proc # 5: svc   B/ /S  trm: 0 1731:com.tencent.mobileqq:MSF/u0a96 (started-services)
    Proc # 2: svc   B/ /S  trm: 0 2782:com.android.system:remote/1000 (service)
        com.android.system/com.baidu.location.f<=Proc{2514:com.android.system/1000}
    Proc # 1: svc   B/ /S  trm: 0 2160:com.huaqin.festivalwallpaper/u0a36 (started-services)
    Proc #28: svcb  B/ /S  trm: 0 1542:com.android.gallery3d/u0a41 (started-services)
    Proc #27: svcb  B/ /S  trm: 0 2028:com.mediatek.atci.service/1000 (started-services)
    Proc #26: svcb  B/ /S  trm: 0 2368:org.simalliance.openmobileapi.service:remote/u0a67 (started-services)
    Proc #13: svcb  B/ /S  trm: 0 2722:com.android.factoryservice/1000 (started-services)
    Proc # 8: svcb  B/ /S  trm: 0 1957:com.tencent.mm:push/u0a95 (started-services)
    Proc # 6: svcb  B/ /S  trm: 0 2659:com.tencent.mm/u0a95 (started-services)
    Proc # 4: cch   B/ /CE trm: 0 2620:com.android.providers.calendar/u0a1 (cch-empty)
    Proc # 3: cch   B/ /CE trm: 0 2764:android.process.acore/u0a3 (cch-empty)
    Proc #10: cch+2 B/ /CE trm: 0 2067:com.android.calendar/u0a20 (cch-empty)
    Proc # 9: cch+2 B/ /CE trm: 0 2737:com.android.email/u0a34 (cch-empty)
    Proc #12: cch+4 B/ /CE trm: 0 2404:com.android.contacts/u0a3 (cch-empty)
    Proc #11: cch+4 B/ /CE trm: 0 2607:com.android.deskclock/u0a29 (cch-empty)
    Proc #24: cch+6 B/ /CE trm: 0 2532:com.adups.fota/u0a39 (cch-empty)
    Proc #23: cch+6 B/ /CE trm: 0 2206:com.adups.fota.sysoper/1000 (cch-empty)
    Proc #22: cch+6 B/ /CE trm: 0 2301:com.iLoong.base.themebox/u0a60 (cch-empty)
    Proc #21: cch+6 B/ /CE trm: 0 2331:com.mediatek.schpwronoff/1000 (cch-empty)
    Proc #20: cch+6 B/ /CE trm: 0 2640:com.android.musicfx/u0a56 (cch-empty)
    Proc #19: cch+6 B/ /CE trm: 0 2460:com.android.mms/u0a9 (cch-empty)
    Proc #18: cch+6 B/ /CE trm: 0 2387:com.mediatek.ppl/1000 (cch-empty)
    Proc #17: cch+6 B/ /CE trm: 0 2435:com.mediatek.op01.plugin/1000 (cch-empty)
    Proc #16: cch+6 B/ /CE trm: 0 2237:com.mediatek.mediatekdm/1000 (cch-empty)
    Proc #15: cch+6 B/ /CE trm: 0 2705:com.android.quicksearchbox/u0a65 (cch-empty)

最终要的信息是可以看到activity 堆栈的信息:

Running activities (most recent first):
      TaskRecord{42dde978 #3 A=android.task.mms U=0 sz=1}
        Run #2: ActivityRecord{42ddcd78 u0 com.android.mms/.ui.ConversationList t3}
      TaskRecord{4287d4b0 #5 A=com.android.settings U=0 sz=1}
        Run #1: ActivityRecord{424d0798 u0 com.android.settings/.Settings t5}
      TaskRecord{427e5990 #6 A=com.android.camera U=0 sz=1}
        Run #0: ActivityRecord{4270b068 u0 com.android.gallery3d/com.android.camera.CameraLauncher t6}

    mResumedActivity: ActivityRecord{42ddcd78 u0 com.android.mms/.ui.ConversationList t3}

  mFocusedActivity: ActivityRecord{42ddcd78 u0 com.android.mms/.ui.ConversationList t3}

查看当前resume的是哪个activity:

adb shell dumpsys activity | grep mFocusedActivity


运行后可以发现我的手机当前运行的activity是:

mFocusedActivity: ActivityRecord{42ddcd78 u0 com.android.mms/.ui.ConversationList t3}

ConversationList.java界面,也就是短信息列表的界面。


Android使用adb获得activity堆栈信息