不要试图完全用Java的思想来理解Android的框架,Android只是将Java作为编程语言而已。
In core Java programs we need a main()
method, because while executing the byte code the JVM will search for the main()
method in the class and start executing there.
In the case of Android, the Dalvik Virtual Machine is designed to find a class which is a subclass of Activity
and which is set as a LAUNCHER to start the execution of the application from its onCreate()
method, so there is no need of a main()
method.
For more information see the life cycle of Activity
.
在核心Java程序中,我们需要一个main()
方法,因为在执行字节码时,JVM将在类中搜索main()
方法并在那里开始执行。
在Android中,Dalvik虚拟机的设计目的是寻找一个类,这个类是Activity的一个子类,它被设置为一个启动程序,从其onCreate()
方法开始执行应用程序,因此不需要main()
方法。
有关更多信息,请参见活动的生命周期。
参考:
https://segmentfault.com/q/1010000019173670/
https://stackoverflow.com/questions/9293329/where-is-main-in-android
https://blog.csdn.net/weixin_40774605/article/details/101430102