Using "adb logcat" Command to Track the Lifecycle of an Application

This section provides a tutorial example how to use the 'adb logcat' command to track the lifecycle of an application. The 'events' log buffer provides log entries for each Activity callback method.

In previous tutorials, we have learned how to use the "adb logcat" command options and arguments filter out log entries and control the output format. Now let's try to use the "adb logcat" to watch how my applications get executed on the device.

1. Run the "adb logcat" command to dump all log entries from "ActivityManager" in the "main" log buffer and leave it there running:

C:\herong>\local\android-sdk-windows\platform-tools\adb logcat -c

C:\herong>\local\android-sdk-windows\platform-tools\adb logcat \
   ActivityManager:V *:S

2. Go to the emulator. Launch my 2 example applications, "AboutAndroid" and "AndroidView".

3. Look at the "adb logcat" window. The following log entries are printed out:

I/ActivityManager(   77): START {act=android.intent.action.MAIN \
   cat=[android.intent.category.LAUNCHER] flg=0x10200000 \
   cmp=com.herongyang/.AboutAndroid} from pid 172
I/ActivityManager(   77): START {act=android.intent.action.MAIN \
   cat=[android.intent.category.HOME] flg=0x10200000 \
   cmp=com.android.launcher/com.android.launcher2.Launcher} from \
   pid 77
I/ActivityManager(   77): START {act=android.intent.action.MAIN \
   cat=[android.intent.category.LAUNCHER] flg=0x10200000 \
   cmp=com.herongyang.view/.AndroidView} from pid 172
I/ActivityManager(   77): Displayed com.herongyang.view/.AndroidView: \
   +1s334ms

4. Run the "adb logcat" command to dump all log entries in the "events" buffer and leave it there running:

C:\herong>\local\android-sdk-windows\platform-tools\adb logcat \
   -b events -c

C:\herong>\local\android-sdk-windows\platform-tools\adb logcat \
   -b events *:V

5. Go to the emulator. Launch my 2 example applications, "AboutAndroid" and "AndroidView". Also click some buttons on "AndroidView".

6. Look at the "adb logcat" window. The following log entries are printed out:

I/am_create_activity(   77): [1095000544,13, \
   com.herongyang/.AboutAndroid,android.intent.action.MAIN,NULL,NULL,\
   270532608]
I/am_pause_activity(   77): [1095117944, \
   com.android.launcher/com.android.launcher2.Launcher]
I/am_on_paused_called(  172): com.android.launcher2.Launcher
I/am_restart_activity(   77): [1095000544,13, \
   com.herongyang/.AboutAndroid]
I/binder_sample(  172): [android.app.IActivityManager,19,82, \
   com.android.launcher,16]
I/am_on_resume_called(  506): com.herongyang.AboutAndroid
I/activity_launch_time(   77): [1095000544, \
   com.herongyang/.AboutAndroid,903,903]
I/am_pause_activity(   77): [1095000544,com.herongyang/.AboutAndroid]
I/am_on_paused_called(  506): com.herongyang.AboutAndroid
I/am_task_to_front(   77): 2
I/am_new_intent(   77): [1095234520,2, \
   com.android.launcher/com.android.launcher2.Launcher, \
   android.intent.action.MAIN,NULL,NULL,274726912]
I/am_resume_activity(   77): [1095117944,2, \
   com.android.launcher/com.android.launcher2.Launcher]
I/am_on_resume_called(  172): com.android.launcher2.Launcher
I/am_create_task(   77): 14
I/am_create_activity(   77): [1095317016,14, \
   com.herongyang.view/.AndroidView,android.intent.action.MAIN,NULL, \
   NULL,270532608]
I/am_pause_activity(   77): [1095117944, \
   com.android.launcher/com.android.launcher2.Launcher]
I/am_on_paused_called(  172): com.android.launcher2.Launcher
I/am_restart_activity(   77): [1095317016,14, \
   com.herongyang.view/.AndroidView]
I/am_on_resume_called(  488): com.herongyang.view.AndroidView
I/activity_launch_time(   77): [1095317016,
   com.herongyang.view/.AndroidView,974,974]
I/binder_sample(  172): [android.app.IActivityManager,19,1189, \
   com.android.launcher,100]
I/am_finish_activity(   77): [1095317016,14, \
   com.herongyang.view/.AndroidView,app-request]
I/am_pause_activity(   77): [1095317016, \
   com.herongyang.view/.AndroidView]
I/am_on_paused_called(  488): com.herongyang.view.AndroidView
I/am_resume_activity(   77): [1095117944,2, \
   com.android.launcher/com.android.launcher2.Launcher]
I/am_on_resume_called(  172): com.android.launcher2.Launcher
I/am_destroy_activity(   77): [1095317016,14, \
   com.herongyang.view/.AndroidView,finish-imm]
I/binder_sample(  488): [android.view.IWindowSession,3,275, \
   com.herongyang.view,55]

Those "am_on_*" log entries from the "events" log buffer record clearly the lifecycle of both applications, com.herongyang.AboutAndroid and com.herongyang.view.AndroidView.

What do you think? Are those log entries from the "main" and "events" log buffers useful to you?

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

 AboutAndroid - Application to Retrieve System Information

 android.app.Activity Class and Activity Lifecycle

 View Objects and Layout Resource Files

Using "adb logcat" Command for Debugging

 "adb logcat" Command - Displaying System Logs

 "adb logcat" Command Options and Log Buffers

 "adb logcat -v" Command - Log Format Control

 "adb logcat" Command Arguments - Output Filters

Using "adb logcat" Command to Track the Lifecycle of an Application

 Java Exceptions in AndroidRuntime Error Log

 Build Process and Package File Content

 Building Your Own Web Browser

 Android Command Line Shell

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials

 References

 Full Version in PDF/EPUB