Android通过ADB命令获取当前运行的Activity

来源:互联网 发布:mac百度云怎么打开种子 编辑:程序博客网 时间:2024/06/10 01:16

Android还为开发者提供了adb(Android Debug Bridge),这是非常强大的调试工具。最常用的自然是logcat来显示日志记录。

方法一:
1、cmd命令中输入:adb shell 进入shell命令模式
2、shell中输入:logcat | grep ActivityManager 真机运行应用,可以实时 查看当前正在运行的Activity;

I/ActivityManager(  936): START u0 {cmp=com.example.chenzongwen.myapplication/.LeakActivity} from uid 10251 from pid 1630 on display 0D/ActivityManager(  936): Delay resumeKeyDispatchingLocked() to avoid deadlock.I/ActivityManager(  936): [AppLaunch] Displayed Displayed com.example.chenzongwen.myapplication/.LeakActivity: +155msD/ActivityManager(  936): AP_PROF:AppLaunch_LaunchTime:com.example.chenzongwen.myapplication/.LeakActivity:155:20438126D/ActivityManager(  936): ACT-IDLE_NOW_MSG from windowsVisible() for idle: ActivityRecord{379aa884 u0 com.example.chenzongwen.myapplication/.LeakActivity t29}

com.example.chenzongwen.myapplication 为包名 LeakActivity 是当前活动的activity。

方法二:
1.cmd命令中输入:adb shell dumpsys activity activities
查看

    Running activities (most recent first):      TaskRecord{35e0a397 #1 A=com.oppo.launcher U=0 sz=1}        Run #0: ActivityRecord{1adfa134 u0 com.oppo.launcher/.Launcher t1}    mLastPausedActivity: ActivityRecord{1adfa134 u0 com.oppo.launcher/.Launcher t1}  mFocusedActivity: ActivityRecord{379aa884 u0 com.example.chenzongwen.myapplication/.LeakActivity t29}  mFocusedStack=ActivityStack{47d984 stackId=1, 3 tasks} mLastFocusedStack=ActivityStack{47d984 stackId=1, 3 tasks}  mSleepTimeout=false  mCurTaskId=29  mUserStackInFront={}  mActivityContainers={0=ActivtyContainer{0}A, 1=ActivtyContainer{1}A}[BMW]FLOATING STACK INFO:  Display Info:ActivityDisplay={0 numStacks=2 numFrontFloatStacks=0 numBackFloatStacks=0}  Front Float Stacks(from top to bottom):  Back Float Stacks:

com.example.chenzongwen.myapplication 为包名 LeakActivity 是当前活动的activity。

0 0
原创粉丝点击