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?