GameActivityCallbacks

#include <GameActivity.h>

These are the callbacks the framework makes into a native application.

Summary

All of these callbacks happen on the main thread of the application. By default, all callbacks are NULL; set to a pointer to your own function to have it called.

Public attributes

onConfigurationChanged)(GameActivity *activity)
void(*
The current device AConfiguration has changed.
onDestroy)(GameActivity *activity)
void(*
GameActivity is being destroyed.
onKeyDown)(GameActivity *activity, const GameActivityKeyEvent *event)
bool(*
Callback called for every key down event on the GameActivity SurfaceView.
onKeyUp)(GameActivity *activity, const GameActivityKeyEvent *event)
bool(*
Callback called for every key up event on the GameActivity SurfaceView.
onNativeWindowCreated)(GameActivity *activity, ANativeWindow *window)
void(*
The drawing window for this native activity has been created.
onNativeWindowDestroyed)(GameActivity *activity, ANativeWindow *window)
void(*
The drawing window for this native activity is going to be destroyed.
onNativeWindowRedrawNeeded)(GameActivity *activity, ANativeWindow *window)
void(*
The drawing window for this native activity needs to be redrawn.
onNativeWindowResized)(GameActivity *activity, ANativeWindow *window, int32_t newWidth, int32_t newHeight)
void(*
The drawing window for this native activity has been resized.
onPause)(GameActivity *activity)
void(*
GameActivity has paused.
onResume)(GameActivity *activity)
void(*
GameActivity has resumed.
onSaveInstanceState)(GameActivity *activity, SaveInstanceStateRecallback recallback, void *context)
void(*
The framework is asking GameActivity to save its current instance state.
onStart)(GameActivity *activity)
void(*
GameActivity has started.
onStop)(GameActivity *activity)
void(*
GameActivity has stopped.
onTextInputEvent)(GameActivity *activity, const GameTextInputState *state)
void(*
Callback called for every soft-keyboard text input event.
onTouchEvent)(GameActivity *activity, const GameActivityMotionEvent *event)
bool(*
Callback called for every MotionEvent done on the GameActivity SurfaceView.
onTrimMemory)(GameActivity *activity, int level)
void(*
The system is running low on memory.
onWindowFocusChanged)(GameActivity *activity, bool hasFocus)
void(*
Focus has changed in this GameActivity's window.
onWindowInsetsChanged)(GameActivity *activity)
void(*
Callback called when WindowInsets of the main app window have changed.

Public attributes

onConfigurationChanged

void(* GameActivityCallbacks::onConfigurationChanged)(GameActivity *activity)

The current device AConfiguration has changed.

The new configuration can be retrieved from assetManager.

onDestroy

void(* GameActivityCallbacks::onDestroy)(GameActivity *activity)

GameActivity is being destroyed.

See Java documentation for Activity.onDestroy() for more information.

onKeyDown

bool(* GameActivityCallbacks::onKeyDown)(GameActivity *activity, const GameActivityKeyEvent *event)

Callback called for every key down event on the GameActivity SurfaceView.

Ownership of event is maintained by the library and it is only valid during the callback.

onKeyUp

bool(* GameActivityCallbacks::onKeyUp)(GameActivity *activity, const GameActivityKeyEvent *event)

Callback called for every key up event on the GameActivity SurfaceView.

Ownership of event is maintained by the library and it is only valid during the callback.

onNativeWindowCreated

void(* GameActivityCallbacks::onNativeWindowCreated)(GameActivity *activity, ANativeWindow *window)

The drawing window for this native activity has been created.

You can use the given native window object to start drawing.

onNativeWindowDestroyed

void(* GameActivityCallbacks::onNativeWindowDestroyed)(GameActivity *activity, ANativeWindow *window)

The drawing window for this native activity is going to be destroyed.

You MUST ensure that you do not touch the window object after returning from this function: in the common case of drawing to the window from another thread, that means the implementation of this callback must properly synchronize with the other thread to stop its drawing before returning from here.

onNativeWindowRedrawNeeded

void(* GameActivityCallbacks::onNativeWindowRedrawNeeded)(GameActivity *activity, ANativeWindow *window)

The drawing window for this native activity needs to be redrawn.

To avoid transient artifacts during screen changes (such resizing after rotation), applications should not return from this function until they have finished drawing their window in its current state.

onNativeWindowResized

void(* GameActivityCallbacks::onNativeWindowResized)(GameActivity *activity, ANativeWindow *window, int32_t newWidth, int32_t newHeight)

The drawing window for this native activity has been resized.

You should retrieve the new size from the window and ensure that your rendering in it now matches.

onPause

void(* GameActivityCallbacks::onPause)(GameActivity *activity)

GameActivity has paused.

See Java documentation for Activity.onPause() for more information.

onResume

void(* GameActivityCallbacks::onResume)(GameActivity *activity)

GameActivity has resumed.

See Java documentation for Activity.onResume() for more information.

onSaveInstanceState

void(* GameActivityCallbacks::onSaveInstanceState)(GameActivity *activity, SaveInstanceStateRecallback recallback, void *context)

The framework is asking GameActivity to save its current instance state.

See the Java documentation for Activity.onSaveInstanceState() for more information. The user should call the recallback with their data, its length and the provided context; they retain ownership of the data. Note that the saved state will be persisted, so it can not contain any active entities (pointers to memory, file descriptors, etc).

onStart

void(* GameActivityCallbacks::onStart)(GameActivity *activity)

GameActivity has started.

See Java documentation for Activity.onStart() for more information.

onStop

void(* GameActivityCallbacks::onStop)(GameActivity *activity)

GameActivity has stopped.

See Java documentation for Activity.onStop() for more information.

onTextInputEvent

void(* GameActivityCallbacks::onTextInputEvent)(GameActivity *activity, const GameTextInputState *state)

Callback called for every soft-keyboard text input event.

Ownership of state is maintained by the library and it is only valid during the callback.

onTouchEvent

bool(* GameActivityCallbacks::onTouchEvent)(GameActivity *activity, const GameActivityMotionEvent *event)

Callback called for every MotionEvent done on the GameActivity SurfaceView.

Ownership of event is maintained by the library and it is only valid during the callback.

onTrimMemory

void(* GameActivityCallbacks::onTrimMemory)(GameActivity *activity, int level)

The system is running low on memory.

Use this callback to release resources you do not need, to help the system avoid killing more important processes.

onWindowFocusChanged

void(* GameActivityCallbacks::onWindowFocusChanged)(GameActivity *activity, bool hasFocus)

Focus has changed in this GameActivity's window.

This is often used, for example, to pause a game when it loses input focus.

onWindowInsetsChanged

void(* GameActivityCallbacks::onWindowInsetsChanged)(GameActivity *activity)

Callback called when WindowInsets of the main app window have changed.

Call GameActivity_getWindowInsets to retrieve the insets themselves.