Android - Activity constructor

前端 未结 4 848
执念已碎
执念已碎 2020-12-20 09:06

I noticed that using the shortcut Alt + Insert and selecting the builders, it tries to create a constructor with each private property (e.g. cManager

4条回答
  •  生来不讨喜
    2020-12-20 09:15

    Android activities can have constructors as long as they take zero arguments. And in fact there is such a constructor as soon as you initialize any field when declaring it.

    But as your log says, System services not available to Activities before onCreate(), so you can't call getSystemService from the constructor.

    So the code in https://stackoverflow.com/a/28636652/53974 is correct, but the reason isn't.

提交回复
热议问题