Initialize views of activity in android -


is necessary initialize views of activity in oncreate() only. can tell me best initializations of views of activity.

thanks

  1. no need initialize view if not modify it.
  2. you can initialize in activity lifecycle wish(before accessing).
  3. but is said best practice initialize in oncreate().

why:

  1. if see lifecycle oncreate called when app page not shown. onstart called when app partially visible & onresume called when visible. so, want ready before seeing it. 1 reason.

  2. another findviewbyid bit more expensive. so, don't want see when app visible.

  3. onstart & onresume may call multiple time when go page. so, it's preferable initialize once , multiple time.

so, choice yours now.


Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -