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
That runs but there is no main!!!
Of course. Many things that you might think of as a Java "application" do not have their own main()
method. For example, IIRC, servlets, WARs, and the like do not have main()
methods -- the main()
method, if there is one, is in the container.
But onCreate is an entry point?
onCreate()
is a method.
What if there is more than one activity... is there a hierarchy to these built in event handlers?
Not really.
OnCreate trumps everything else?
Not really.
Otherwise, how would the app know what to run or where to enter the program?
An app does not "know what to run or where to enter the program".
An Android application is a basket of components. Some components may be tied to icons in a home screen launcher. Some components may be tied to scheduled timers, like cron jobs or Windows scheduled tasks. Some components may be tied to system events, such as when the device is placed into or removed from a car dock. Those components will be automatically created and used when appropriate (e.g., when a user taps the icon in the home screen launcher). Yet other components are only created and used when your code specifically asks for them.
Thinking of an Android application as if it were a monolithic console-mode Java program will cause you no end of trouble.
I found this particularly useful...
http://developer.android.com/guide/topics/fundamentals.html#appcomp
Applets don't have main() methods either. It just depends on how your code is packaged.
In Java, there is a main even if it isn't listed as main()
. The page you get after the icon click, whatever its name, is the main()
.
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
An android programmer should learn this like the back of their hands it simply explains everything and would help in the future when creating activities. http://developer.android.com/reference/android/app/Activity.html