Search code examples
dalvikdex

How does dalvikvm understand the starting point of android application


I can successfully run a simple java program in dalvikvm by converting the java class into dex file. But when I try to run android application by converting its class files into dex, it says static main(String args[]) not found.

Android application does not contain static main() method.

So where does dalvikvm start executing an android application or how does it find the static main() method in android application???


Solution

  • Android determines your app's entry point based on the AndroidManifest.xml shipped with your app. Specifically, Android determines which intent was sent to the app (to cause it to launch), and will instantiate the appropriate Activity and call its onCreate method. This creation process is overseen by a wrapper process called app_process, which calls into dalvik directly and sets up the app execution environment.

    Dalvik itself behaves like a normal Java JVM in most regards; therefore, running a jar or dex with Dalvik will still expect a main method, as with normal Java.