2

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?

Community
  • 1
  • 1
committedandroider
  • 8,711
  • 14
  • 71
  • 126
  • possible duplicate of [Difference between onCreate() and onStart()?](http://stackoverflow.com/questions/6812003/difference-between-oncreate-and-onstart) – Pratik Butani Jun 26 '14 at 07:23
  • no im just wondering how onstart "can be called when the activity is becomgin visible to the user" after setContentView has been called in onCreate – committedandroider Jun 26 '14 at 07:27

2 Answers2

4

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.

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • when you call setcontentview in onCreate, wont that make your activity visible? sorry might of phrased the question wrong. So onStart will be called when the activity is already visible to the user? – committedandroider Jun 26 '14 at 07:30
  • 1
    @committedandroider No. The onResume() method makes visible of Activity. – Pankaj Kumar Jun 26 '14 at 09:17
1
onCreate    called when activity is first created.
onStart     called when activity is becoming visible to the user.

and also

onResume    called when activity will start interacting with the user.
onPause     called when activity is not visible to the user.
onStop      called when activity is no longer visible to the user.
onRestart   called after your activity is stopped, prior to start.
onDestroy   called before the activity is destroyed.

For difference between onCreate and onStart see this link

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138