“This is the 17th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
The introduction
In the actual development of Android or project support, I wonder if you guys have ever encountered such a situation that you need to locate the Activity information of a certain interface. Although the Android IDE tool can do this, sometimes we hope that there is a faster way to locate the Activity information of this interface. This is where the adb shell command comes into its own.
Plan a
adb shell dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'
Copy the code
The output is straightforward, listing all the pages you have opened in the most recent order, with TaskRecord showing the queried record followed by the package name and the Activity name
Running activities (most recent first):
TaskRecord{c9e9ecb #82 A=com.android.deskclock U=0 StackId=1 sz=1}
Run #0: ActivityRecord{cb1be5c u0 com.android.deskclock/.DeskClock t82}
Running activities (most recent first):
TaskRecord{195f930 #78 I=com.android.launcher3/.Launcher U=0 StackId=0 sz=1}
Run #0: ActivityRecord{3ef71d8 u0 com.android.launcher3/.Launcher t78}
Running activities (most recent first):
TaskRecord{feda6a8 #81 A=com.android.systemui U=0 StackId=5 sz=1}
Run #0: ActivityRecord{30d91fc u0 com.android.systemui/.recents.RecentsActivity t81}
Copy the code
Scheme 2
adb shell dumpsys activity | grep -i run
Copy the code
The output is straightforward, listing all the pages you’ve opened in the most recent order.
service_reset_run_duration=60000 Running activities (most recent first): Run #1: ActivityRecord{cb1be5c u0 com.android.deskclock/.DeskClock t82} Run #0: ActivityRecord{da6223d u0 com.android.gallery3d/.app.GalleryActivity t83} Running activities (most recent first): Run #0: ActivityRecord{3ef71d8 u0 com.android.launcher3/.Launcher t78} Running activities (most recent first): Run #0: ActivityRecord{30d91fc u0 com.android.systemui/.recents.RecentsActivity t81} ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes) User #0: state=RUNNING_UNLOCKEDCopy the code
Scheme three outputs the activity stack
adb shell dumpsys activity top | grep ACTIVITY
Copy the code
The output is straightforward, listing the pages you have opened, in reverse order here. The top-level activity comes last.
Scheme 4 outputs interactive activities in the foreground
adb shell dumpsys window | grep mCurrentFocus
Copy the code
130|XXX:/ # dumpsys window | grep mCurrentFocus
mCurrentFocus=Window{31e5cd4 u0 com.android.gallery3d/com.android.gallery3d.app.GalleryActivity}
Copy the code
conclusion
The AMS dumpsys
This is done with the help of dumpsys, a built-in Android terminal command that can be found in AMS dumpsys.
Adb loacat command
The adb logcat command is also recommended here