androidlifecycleoncreateonstart

Is onStart called when the screen is already visible or becoming visible?


I looked on another thread on stack overflow (src: Difference between onCreate() and onStart()?) That thread described the onStart() method as "Called when the activity is becoming visible to the user". However in that same answer and in many overrides of the oncreate method, i see setContentView called in onCreate. Wont that make the screen visible then? Therefore in that situation(where setContentView is called in onCreate), is onStart() called after the screen becomes visible to the user but before the user can interact with it?


Solution

  • The chances of onStart() can be called multiple times.

    onCreate() : Called when the activity is first created.

    onStart() : Called when the activity is becoming visible to the user.

    Now look into the graph given to Difference between onCreate() and onStart()? post. onStart() can be called multiple times, in case if process is not killed (if activity has been called again.)

    So if you set view at onStart(), you will need to initialize view into onStart() or later (i.e. onResume() ). This will be a repetitive process. Is not it a bad practice to initialize view again and again?

    Hope I am clear here.