Search code examples
javaandroidswingandroid-activitylauncher

Does Android Create instances of the Activity classes or how else does it work?


Having programmed for just over 6 months in Java i decided to give android a shot,but it looks like android merely uses the Java Syntax and all else differs

Example: I can see under app/src/java/MainApplication... that The Activity MainApplication extends Activity and has onCreate() methods etc , but what i don't get is how all this works, which method in the launcher activity runs first and how?

Can you draw an analogy between java Programs in Jar files ,say like how the class declared in manifest is launched and its main method runs and how android works?

I find the whole Android framework to be very different and confusing compared to the Java, Swing, AWT and event handling model of what i practiced so far, Please help!

How is onCreate() called without creating an instance of the class and calling the method on the Object, how is it called without an Object as the method is not static too?

PS:I'm taking Udacity's android course


Solution

  • Basically it works as follows:

    1. Application entry points such as activities are declared in the manifest file and it is bundled with the application APK.

    2. The activity class is instantiated by name declared in the manifest, using reflection.

    3. The class instance is set up (e.g. Context, Configuration) and its onCreate() and other lifecycle methods are called.

    For code-level details, see e.g. performLaunchActivity() in ActivityThread.