Why is onCreate() in Activity protected?

后端 未结 4 1154
旧巷少年郎
旧巷少年郎 2021-01-02 06:05

Why is the onCreate() in Activity protected?

or I should ask: why does it work?

Protected method can only be called in the inside of the class itself or it\'

4条回答
  •  失恋的感觉
    2021-01-02 06:46

    Why should you care wether the onCreate is protected? Is protected because logically it should not be accessed by other class different from Activities. How does Android launch the Activity? There are a lot of ways of doing that, specially if you're the one who designed the framework, the solution could be that is being invoked on the constructor (a possibility) o by other mechanisms like reflection with the appropriate privileges, etc.

    The onClick is public because it could be set or handled by external classes that not necessary are your Activity. By this I mean that class A could be able to handle the onClick event of the Activity.

提交回复
热议问题