- 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
- Bootstrap Site Blueprints Volume II
- .NET之美:.NET關(guān)鍵技術(shù)深入解析
- 編程珠璣(續(xù))
- 基于免疫進化的算法及應(yīng)用研究
- Python編程完全入門教程
- 深入淺出RxJS
- Service Mesh實戰(zhàn):基于Linkerd和Kubernetes的微服務(wù)實踐
- 匯編語言編程基礎(chǔ):基于LoongArch
- Kivy Cookbook
- 大學(xué)計算機基礎(chǔ)實驗指導(dǎo)
- LabVIEW入門與實戰(zhàn)開發(fā)100例(第4版)
- Java Web動態(tài)網(wǎng)站開發(fā)(第2版·微課版)
- Qt 5.12實戰(zhàn)
- C語言程序設(shè)計實驗指導(dǎo)與習(xí)題精解
- Java基礎(chǔ)案例教程(第2版)