官术网_书友最值得收藏!

First case

Run your application. Then just go back and leave it. Kill the app. Open Android Monitor, and from the device drop-down list, choose your device instance (emulator or real device). From the next drop-down list, choose the Journaler application package. Observe the following Logcat output:

You will notice the log messages we put in our source code.

Let's check how many times during our interaction with the application we entered the onCreate() and onDestroy() methods. Position your cursor on the search field and type on create. Observe the change in content--there is only one entry when we expected two: one for the main Application class and one for the main activity. Why did this happen? We will find out later:

What does our output contain? It contains the following:

06-27: This is the date the event occurred.

11:37:59.914: This is the time the event occurred.

6713-6713/?: This is the process and thread identifier with the package. Process and thread identifiers are the same if the application has only one thread.

V/Journaler: This is the log level and tag.

[ ON CREATE ]: This is the log message.

Change the filter to on destroy. The content changes to the following:

06-27 11:38:07.317 6713-6713/com.journaler.complete.dev V/Journaler: [ ON DESTROY ]

In your case, you will have different date, time, and pid/tid values.

From the drop-down list, change your filtering from Verbose to Warn. Keep the value for the filter! You will notice that your Logcat is now empty. It's empty because there is no warning messages with the message text containing on destroy. Remove the filter text and return to Verbose level.

Run your application. Lock your screen and unlock it a few times in a row. Then, close and kill the Journaler application. Observe the following Logcat output:

As you can see, it's noticeably entering lifecycle states for pausing and resuming. Finally, we kill our app and an onDestroy() event is triggered. You can see it in Logcat.

If it's easier for you, you can use Logcat from a terminal. Open the terminal and execute the following command line:

adb logcat
主站蜘蛛池模板: 富锦市| 武胜县| 曲沃县| 杂多县| 吴旗县| 万载县| 海城市| 德保县| 阿坝县| 内乡县| 安庆市| 迁西县| 黄冈市| 韩城市| 读书| 永嘉县| 德保县| 雷波县| 新津县| 汉中市| 济宁市| 聂荣县| 彰化市| 固始县| 固始县| 原阳县| 凤城市| 呼伦贝尔市| 鄄城县| 丰城市| 海宁市| 油尖旺区| 潞城市| 尼勒克县| 葵青区| 哈尔滨市| 长春市| 哈密市| 都江堰市| 林州市| 南和县|