简体   繁体   中英

adb logcat - missing logs

I am fairly new to Android and I want to understand the activity lifecycle. The documentation on the Android developer site is really great for that, but I want to see the lifecycle in action.

So, I create a new simple project and in the main activity, I overwrite the methods onCreate() , onDestroy() , onStart() , onStop() , onResume() and onPause() and add a log statement to each of it.

Then, I fire up the simulator and open the app, change orientation, switch to another app and so on and have a look on the log statements to see what's going on.

I notice strange behaviours. For example: I start the app for the very first time:

02-21 10:22:32.470 I/MainActivity( 2114): onCreate called.
02-21 10:22:32.520 I/MainActivity( 2114): onStart called.
02-21 10:22:32.520 I/MainActivity( 2114): onResume called.

That's what I expected, fine. Then, I open the recents apps switcher.

02-21 10:24:01.520 I/MainActivity( 2114): onPause called.
02-21 10:24:01.520 I/MainActivity( 2114): onStop called.

I switch back to it:

02-21 10:24:26.050 I/MainActivity( 2114): onStart called.
02-21 10:24:26.050 I/MainActivity( 2114): onResume called.

So far, so good. Then, I open the app switcher again:

02-21 10:24:31.670 I/MainActivity( 2114): onStop called.

Here it's getting weird. Where is onPause() ? In my opinion, this method has to be called before onStop() is called.

These log messages are examples, sometimes the behaviour is slightly different and it is not always predictable. But always some log statements are missing.

I googled this and found something about "rotating" logs. My problem is: I do not understand why it is difficult to get all log statements. Period. Maybe there are some technical barriers, but from a developer point of view, while learning about a new ecosystem, this is just frustrating.

Am I missing something here? Is there a simple solution for getting all log entries?

from https://developer.android.com/reference/android/util/Log.html :

Tip: Don't forget that when you make a call like

Log.v(TAG, "index=" + i);

that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.

From: http://developer.android.com/tools/debugging/debugging-log.html#filteringOutput

Every Android log message has a tag and a priority associated with it.

  • The tag of a log message is a short string indicating the system component from which the message originates (for example, "View" for the view system).
  • The priority is one of the following character values, ordered from lowest to highest priority:
    • V — Verbose (lowest priority)
    • D — Debug
    • I — Info
    • W — Warning
    • E — Error
    • F — Fatal
    • S — Silent (highest priority, on which nothing is ever printed)

You may want to look into:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM