How an App Actually Runs

1. Starting from the Launch Entry Point

To understand how any Android app launches, you have to start with the global configuration file: AndroidManifest.xml.

Open AndroidManifest.xml and look for the following code:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>Code language: HTML, XML (xml)

This snippet does three key things:

  1. Register the Activity: MainActivity must be declared in AndroidManifest.xml; otherwise, the system won’t recognize it and can’t use it.
  2. Declare the Main Entry: <action android:name="android.intent.action.MAIN" /> marks this as the app’s main activity.
  3. Declare the Launcher Entry: <category android:name="android.intent.category.LAUNCHER" /> means this activity is the first thing that starts when you tap the app icon on the home screen.

Only an activity that has both MAIN and LAUNCHER will serve as the app’s launch entry.


2. What Exactly Is an Activity?

An Activity is the storefront of an Android app — everything you see on the screen runs inside an Activity.

Open MainActivity.java under the app/java/ directory. The code looks like this:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}Code language: JavaScript (javascript)

Let’s break it down:

CodeExplanation
extends AppCompatActivityInherits from AppCompatActivity, a backward-compatible Activity that goes as far back as Android 2.1
All activities must extend Activity (or its subclasses)This is a mandatory requirement for Android components
onCreate()A lifecycle method that runs automatically when the activity is created
setContentView(R.layout.activity_main)Loads and binds a layout file to the current activity

3. Separation of Logic and View (Similar to MVC)

Android follows a design philosophy of separating logic from view, similar to the MVC pattern:

  • Logic: Written in Activity classes under the java/ directory
  • View: Written in XML layout files under the res/layout/ directory

setContentView(R.layout.activity_main) is the bridge that connects logic and view — it “plugs” the activity_main.xml layout into MainActivity.


4. Layout File Breakdown

Layout files live in res/layout/activity_main.xml.

Android Studio offers two editing modes:

ModeDescription
DesignVisual drag-and-drop interface, WYSIWYG
TextXML code editing interface

Open activity_main.xml. The core content looks like this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello Foxdevelop" />Code language: HTML, XML (xml)
  • TextView is a basic Android control used for displaying text
  • The android:text attribute specifies what text appears on the control

The “Hello World” (or whatever custom text you set) is defined right here, not in the Java code.


5. Complete Launch Flow Summary

Here’s the full startup process from beginning to end:

User taps the app icon on the home screen
        ↓
System reads AndroidManifest.xml
        ↓
Finds the Activity with MAIN + LAUNCHER (i.e., MainActivity)
        ↓
Creates a MainActivity instance
        ↓
Executes the onCreate() lifecycle method
        ↓
setContentView() loads the activity_main.xml layout
        ↓
The TextView in the layout displays its text
        ↓
Screen shows "Hello World"Code language: CSS (css)

In one sentence:

Config file declares entry → Main activity gets created → onCreate executes → Layout file loads → Controls render to screen


6. Development Tips

  • No need to shut down the emulator every time: After running, if you want to stop the app, just click the 🔴 Stop button on the toolbar. No need to power off or exit the emulator.
  • After modifying code, just click ▶ Run to redeploy and see the changes.

7. Summary

LayerCorresponding FileResponsibility
ConfigurationAndroidManifest.xmlDeclares the entry activity
LogicMainActivity.javaControls activity behavior
Viewactivity_main.xmlDefines interface content

Config file → Main activity → onCreate() method → Load view layout → Screen display

How an App Actually Runs

Leave a Reply

Your email address will not be published. Required fields are marked *