Search guides and the APICtrl K
  1. API reference
  2. Formats and wrappers

android_app.h

An Android app's activity, in C++.

#include <sonore/android_app.h>
On this page

Design notes

NativeActivity, and no Java of our own

Android starts an app as a Java Activity. android.app.NativeActivity is the framework's own one for apps written in C and C++: it loads the library the manifest names and calls ANativeActivity_onCreate in it, then forwards the activity's life -- start, resume, pause, the window, the input queue -- as C callbacks. So an APK built by sonore_add_standalone carries one .so and no dex, and everything an app does runs here, on the activity's MAIN thread, the one Android calls the UI thread.

What this file does with it:

  • Puts the window on the screen: the activity's ANativeWindow is attached to gfx::AndroidSurface, the compositor every native-window peer draws into (gfx/window_android.h).
  • Runs the UI: the main thread's ALooper gets the input queue, a 60 Hz timerfd for the surface's clock while the activity is visible, and the MessageManager's wake-up descriptor, so callAsync() lands on this thread as it does on every other platform.
  • Gives the app a place on disk: HOME is the app's files folder and TMPDIR its cache, which is where every "user folder" and "temporary file" in the SDK then goes. An Android shell's /tmp does not exist for an app.
  • Asks the framework what the C side cannot: the screen's density, whether the app may record audio, and whether the sound is going to headphones. Through JNI on framework classes only, which is why there is no dex.

An app implements ActivityHooks and returns one from sonore_android_make_app (standalone_android.h does, for a plugin's standalone).

Types 2

What an app does when its activity moves: all on the main thread. Every hook is optional; the activity itself keeps the window on the surface.

The state of the one activity this process runs, and its looper wiring.

Functions 28

↑↓ to move↵ to openEvery public name in the headers, and every guide