How can Android source code not have a main method and still run?

前端 未结 13 2454
萌比男神i
萌比男神i 2020-11-30 07:40

I\'ve seen this in a few tutorials now... but how in the world can Android source code not have a main method and still run.

For example (from http://developer.andro

13条回答
  •  时光取名叫无心
    2020-11-30 08:12

    In 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 Android, the Dalvik Virtual Machine is designed to find a class which is a subclass of Activity and which is set to start the execution of the application from its onCreate() method, so there is no need of a main() method.

    The order in which Dalvik Virtual Machine calls methods is based on order of priorities called android life cycle for more information on android life cycle check the link below Android Life Cycle: https://developer.android.com/guide/components/activities/activity-lifecycle.html

提交回复
热议问题