Sobes.tech
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 which finish() is called
  • onStart() — called after onCreate()
  • onResume() — called after onStart()
  • onPause() — called when the activity is finishing
  • onStop() — called after onPause()
  • 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.