Junior — Middle
What messages will appear in the logs if an activity goes through a typical lifecycle but calls finish() in onCreate, after which the completion is logged?
sobes.tech AI
Answer from AI
If the finish() method is called within the activity's onCreate() method, the lifecycle will be as follows:
onCreate()— called, within whichfinish()is calledonStart()— called afteronCreate()onResume()— called afteronStart()onPause()— called when the activity is finishingonStop()— called afteronPause()onDestroy()— called at the end
Logs will display messages corresponding to these method calls. For example:
onCreate()
onStart()
onResume()
onPause()
onStop()
onDestroy()
Thus, despite calling finish() in onCreate(), the activity goes through the full lifecycle but terminates immediately after starting.