When do activity's instance variables get initialized?

前端 未结 2 1640
说谎
说谎 2021-01-22 03:09

In my android application I have a strange bug. An instance variable like below gets assigned to it\'s default value unexpectedly at run time (in this case - false). When do thi

相关标签:
2条回答
  • 2021-01-22 03:42

    Instance variables in Java are initialized when the instance is created.

    Most of the time objects would get instantiated with new.

    In case of activities, they are instantiated by the Android framework using reflection (see Instrumentation#newActivity()). Then initialization for Context is performed and activity onCreate() gets called on the instance.

    For details, have a look at ActivityThread source.

    0 讨论(0)
  • 2021-01-22 03:54

    Java doesn't have "global variables".

    You are talking about instance variables. They are initialized each time a new instance is created.

    0 讨论(0)
提交回复
热议问题