MCPcopy Create free account
hub / github.com/android/ndk-samples / engine_handle_cmd

Function engine_handle_cmd

native-activity/app/src/main/cpp/main.cpp:236–266  ·  view source on GitHub ↗

* The callback for native_app_glue's Activity lifecycle event queue. */

Source from the content-addressed store, hash-verified

234 * The callback for native_app_glue's Activity lifecycle event queue.
235 */
236static void engine_handle_cmd(android_app* app, int32_t cmd) {
237 auto* engine = (Engine*)app->userData;
238 // There are a lot of lifecycle events that we're ignoring here. See
239 // android_native_app_glue.h for the complete list that native_app_glue
240 // handles (which may not be complete if Activity adds new lifecycle
241 // methods!)
242 //
243 // Most applications will need to handle many more of than just this set.
244 // We're getting away with ignoring most events because this app doesn't do
245 // anything interesting.
246 switch (cmd) {
247 case APP_CMD_INIT_WINDOW:
248 // https://developer.android.com/ndk/reference/struct/a-native-activity-callbacks#onnativewindowcreated
249 engine->AttachWindow();
250 break;
251 case APP_CMD_TERM_WINDOW:
252 // https://developer.android.com/ndk/reference/struct/a-native-activity-callbacks#onnativewindowdestroyed
253 engine->DetachWindow();
254 break;
255 case APP_CMD_GAINED_FOCUS:
256 // https://developer.android.com/ndk/reference/struct/a-native-activity-callbacks#onwindowfocuschanged
257 engine->Resume();
258 break;
259 case APP_CMD_LOST_FOCUS:
260 // https://developer.android.com/ndk/reference/struct/a-native-activity-callbacks#onwindowfocuschanged
261 engine->Pause();
262 break;
263 default:
264 break;
265 }
266}
267
268/**
269 * `android_main()` is the entry point for an app using `native_app_glue`.

Callers

nothing calls this directly

Calls 4

AttachWindowMethod · 0.80
DetachWindowMethod · 0.80
PauseMethod · 0.80
ResumeMethod · 0.45

Tested by

no test coverage detected