package com.neuron.el;

import android.app.Activity;
import android.os.Bundle;

/**
 * MainActivity — entry point for native-hello-android.
 *
 * Loads the el native shared library, initialises ElBridge with the Activity
 * reference (required before any widget operations), then hands control to the
 * compiled el program via nativeMain().
 *
 * The el boot sequence (native_init → window_from_manifest → app_build →
 * window_show) runs inside nativeMain. __native_run_loop is a no-op on Android;
 * the Activity lifecycle owns the UI thread after onCreate returns.
 */
public class MainActivity extends Activity {

    static {
        System.loadLibrary("elnative");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Register this Activity with the bridge BEFORE nativeMain so that
        // el_android_init can look up ElBridge methods and __native_init works.
        ElBridge.init(this);
        // Run the compiled el program.
        nativeMain();
    }

    /**
     * Implemented in el_android.c as Java_com_neuron_el_MainActivity_nativeMain.
     * Calls the el program's main(), which runs the full boot sequence.
     */
    private native void nativeMain();
}
