2

Whenever a new Activity is created onCreate is called. Followed by onStart. And onStart is called again when activity is back on to the screen. I know this fundamentals. But, what is the actual difference between when you launch the activity.

I mean to say, when you click on some object on current activity, you start a new activity by startActivity() method with an intent of new activity. Now onCreate() will be called of the second activity and then the onStart(). When will be the activity visible to the user? After onCreate or after onStart? If it is visible after onCreate and before onStart, and I do some of the operations in onStart(), then it will reduce the lag between the user clicking on an object and the screen popping up on screen.

If I move some of the data bindings to onStart will it interfere with the default Activity transitions on lollipop and above (I am not sure about this)?

Is it a good idea to move some of the code to onStart to reduce a lag between click and new activity shown on user's screen? If yes, what kind of code can be safely moved to onStart? Like data bindings, database queries, etc. ?

Any guidance will be much appreciated.

kirtan403
  • 6,899
  • 5
  • 48
  • 95

1 Answers1

2

In the method onCreate the activity actually gets created and then second method onStart gets call at the time of onStart the UI actually get visible to user, for better understanding of activity you need to understand the Activity Life cycle. enter image description here

Pradeep Deshmukh
  • 759
  • 1
  • 8
  • 17
  • So it will be visible after onStart. So no point of skipping some content to onStart. Only when some things need to re-initialize after activity stopped and brought to screen again. – kirtan403 May 28 '16 at 09:02
  • Yes right, but do not put unnecessary heavy objects in onStart() method, you should put it in onCreate() if possible, because onStart() method may get call numbers of time. – Pradeep Deshmukh May 28 '16 at 09:27