更新时间 | 修改意见 |
---|---|
2016-08-02 | 陈敏 |
第7节 ADB工具调试Activity
为了帮助我们深入学习Activity,这里介绍通过ADB工具获取系统中现有Activity信息的方法。
7.1 打印系统Activity信息
用命令行工具进入adb所在的目录,
输入adb shell dumpsys activity activities
,会输出类似如下的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
$ ./adb shell dumpsys activity activities ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities) Display #0 (activities from top to bottom): Stack #0: Task id #178 * TaskRecord{cce8184 #178 I=com.android.launcher3/.Launcher U=0 sz=1} userId=0 effectiveUid=u0a8 mCallingUid=0 mCallingPackage=null intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher3/.Launcher} realActivity=com.android.launcher3/.Launcher autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=1 mTaskToReturnTo=0 rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE Activities=[ActivityRecord{b820c49 u0 com.android.launcher3/.Launcher t178}] askedCompatMode=false inRecents=true isAvailable=true lastThumbnail=null lastThumbnailFile=/data/system/recent_images/178_task_thumbnail.png stackId=0 hasBeenVisible=true mResizeable=false firstActiveTime=1451983947131 lastActiveTime=1451983947131 (inactive for 2501s) * Hist #0: ActivityRecord{b820c49 u0 com.android.launcher3/.Launcher t178} packageName=com.android.launcher3 processName=com.android.launcher3 launchedFromUid=0 launchedFromPackage=null userId=0 app=ProcessRecord{f7b8d6d 25040:com.android.launcher3/u0a8} Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher3/.Launcher } frontOfTask=true task=TaskRecord{cce8184 #178 I=com.android.launcher3/.Launcher U=0 sz=1} taskAffinity=null realActivity=com.android.launcher3/.Launcher baseDir=/system/priv-app/Launcher3/Launcher3.apk dataDir=/data/user/0/com.android.launcher3 stateNotNeeded=true componentSpecified=false mActivityType=1 compat={420dpi} labelRes=0x7f0c0005 icon=0x7f030000 theme=0x7f0e000e config={1.0 310mcc260mnc zh_CN ldltr sw411dp w411dp h659dp 420dpi nrml port finger qwerty/v/v dpad/v s.6} stackConfigOverride={1.0 ?mcc?mnc ?locale ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?} taskDescription: iconFilename=null label="null" color=ff212121 launchFailed=false launchCount=1 lastLaunchTime=-41m41s66ms haveState=false icicle=null state=RESUMED stopped=false delayedResume=false finishing=false keysPaused=false inHistory=true visible=true sleeping=false idle=true fullscreen=true noDisplay=false immersive=false launchMode=2 frozenBeforeDestroy=false forceNewConfig=false mActivityType=HOME_ACTIVITY_TYPE waitingVisible=false nowVisible=true lastVisibleTime=-41m39s31ms Running activities (most recent first): TaskRecord{cce8184 #178 I=com.android.launcher3/.Launcher U=0 sz=1} Run #0: ActivityRecord{b820c49 u0 com.android.launcher3/.Launcher t178} mResumedActivity: ActivityRecord{b820c49 u0 com.android.launcher3/.Launcher t178} mFocusedActivity: ActivityRecord{b820c49 u0 com.android.launcher3/.Launcher t178} mFocusedStack=ActivityStack{c009da2 stackId=0, 1 tasks} mLastFocusedStack=ActivityStack{c009da2 stackId=0, 1 tasks} mSleepTimeout=false mCurTaskId=178 mUserStackInFront={} mActivityContainers={0=ActivtyContainer{0}A} mLockTaskModeState=NONE mLockTaskPackages (userId:packages)= 0:[] mLockTaskModeTasks[] |
它记录下了当前安卓系统中所有的Task,以及每个Task中包含的Activity信息。
例如这里记录了,
- 系统中有一个
Task id
为#178
的Task
; Task
栈中的Activity,从上到下依次是TaskRecord---com.android.launcher3/.Launcher
,一个Activity
;- 并且
com.android.launcher3/.Launcher
这个Activity
是位于前台的Activity
;
这些信息对程序的调试会有很大的帮助。
7.2 ADB启动Activity
用ADB工具启动已知Activity,
1 2 3 4 5 |
$ ./adb shell am start -n 包名/包名.activity名称 //或者 $ ./adb shell am start -n 包名/.activity名称 |
这里的包名就形如:com.android.launcher3,例如
1 2 3 4 5 |
$ ./adb shell am start -n com.android.launcher3/com.android.launcher3.Launcher //或者 $ ./adb shell am start -n com.android.launcher3/.Launcher |
/**************************************************************************/
* 版权声明
* 本教程只在CSDN和安豆网发布,其他网站出现本教程均属侵权。
/**************************************************************************/