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

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -