Inhaltsverzeichnis

std.android.app_glue

android_app-Glue-Schicht: kapselt ANativeActivity in eine android_app-Struktur mit eigenem Thread und vereinfachter Event-Loop. Empfohlener Einstiegspunkt für neue Anwendungen.

std.android · std.android.native_activity · std.android.looper


Typen

Typ Beschreibung
android_app Zentrale App-Struktur (activity, config, savedState, looper, inputQueue, window …)
android_poll_source Event-Quelle mit id und process-Callback

Kommando-Konstanten

Konstante Bedeutung
APP_CMD_START Activity gestartet
APP_CMD_RESUME Activity fortgesetzt
APP_CMD_PAUSE Activity pausiert
APP_CMD_STOP Activity gestoppt
APP_CMD_DESTROY Activity zerstört
APP_CMD_INIT_WINDOW Fenster bereit
APP_CMD_TERM_WINDOW Fenster wird zerstört
APP_CMD_GAINED_FOCUS Fokus erhalten
APP_CMD_LOST_FOCUS Fokus verloren
APP_CMD_LOW_MEMORY Wenig Speicher
APP_CMD_CONFIG_CHANGED Konfiguration geändert (Rotation)

Verwendung

import std.android.app_glue;

fn HandleCommand(app: *android_app, cmd: int64): void {
    if (cmd = APP_CMD_INIT_WINDOW) {
        InitRenderer(app.window);
    }
    if (cmd = APP_CMD_TERM_WINDOW) {
        DestroyRenderer();
    }
}

fn android_main(app: *android_app): void {
    app.onAppCmd := HandleCommand;

    var running: bool := true;
    while (running) {
        var events: int64 := 0;
        var source: *android_poll_source := nil;
        ALooperPollAll(0, nil, &events, &source);
        if (source != nil) {
            source.process(app, source);
        }
        if (app.destroyRequested != 0) {
            running := false;
        }
        RenderFrame();
    }
}

Letzte Aktualisierung: 2026-05-22