Files
android-activity/examples/na-mainloop/README.md
T
Robert Bragg 57b5192366 Update examples
This updates both the examples to Gradle 9 and AGP 9.1

The examples are identical, except that `na-mainloop` is based on
NativeActivity and the `agdk-mainloop` based on GameActivity.

The examples demonstrate:
- Using the `jni` API to define enough bindings to be able to send a Toast
- Using an `android_on_create` entry point for logging initialization
  and JNI initialization
- Using `AndroidApp::run_on_java_main_thread()` to send a toast from the
  Java main / UI thread
- Running an `android_main` event loop, including printing historic
  pointer samples (a new 0.6.1 feature)

The examples support two input actions:
- Lifting your finger in the top-left corner of the screen will show the
  onscreen keyboard
- Lifting your finger in the top-right corner of the screen will hide
  the onscreen keyboard

If you edit and disable `configChanges` in `AndroidManifest.xml` then
these examples can also demonstrate that `android-activity` gracefully
handles repeated `Activity` create -> run -> destroy cycles.
2026-03-23 22:37:54 +00:00

935 B

This is a minimal test application based on NativeActivity that just runs a mainloop based on android_activity::poll_events() and traces the events received without doing any rendering. It also saves and restores some minimal application state.

Since this test doesn't require a custom Activity subclass it's optionally possible to build this example with cargo apk.

Gradle Build

export ANDROID_NDK_HOME="path/to/ndk"
export ANDROID_HOME="path/to/sdk"

rustup target add aarch64-linux-android
cargo install cargo-ndk

cargo ndk -t arm64-v8a -o app/src/main/jniLibs/  build
./gradlew build
./gradlew installDebug

Run with:

adb shell am start -n com.github.realfit_mobile.namainloop/android.app.NativeActivity

Cargo APK Build

export ANDROID_NDK_HOME="path/to/ndk"
export ANDROID_SDK_HOME="path/to/sdk"

rustup target add aarch64-linux-android
cargo install cargo-apk

cargo apk build
cargo apk run