- Mastering Android Development with Kotlin
- Milo? Vasi?
- 352字
- 2021-07-02 15:20:56
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
- Mastering JavaScript Functional Programming
- Learning RxJava
- Apache Spark 2 for Beginners
- Mastering Python Scripting for System Administrators
- Web程序設計(第二版)
- Python Web數據分析可視化:基于Django框架的開發實戰
- Linux C編程:一站式學習
- Building Machine Learning Systems with Python(Second Edition)
- Mastering Adobe Captivate 7
- Python預測分析實戰
- ArcPy and ArcGIS(Second Edition)
- 深入大型數據集:并行與分布化Python代碼
- Android熱門應用開發詳解
- 新手學ASP動態網頁開發
- Mastering Docker(Second Edition)