# 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 ||
|---|---|
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a74ca8180d204497eedb8504804478320)(GameActivity *activity)` | `void(*` The current device AConfiguration has changed. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1aa8b42eeea760cfbc8f196ddb6c15f253)(GameActivity *activity)` | `void(*` [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) is being destroyed. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a87a18d0b0274f6fc623ddfb47a1259bf)(GameActivity *activity, const GameActivityKeyEvent *event)` | `bool(*` Callback called for every key down event on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a6bccb410c3d1df7c75df03b8463c33ae)(GameActivity *activity, const GameActivityKeyEvent *event)` | `bool(*` Callback called for every key up event on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a41e6bde049351e257f966fc56be21093)(GameActivity *activity, ANativeWindow *window)` | `void(*` The drawing window for this native activity has been created. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1aaeee8fa98605768a7e083aec9a9be7a3)(GameActivity *activity, ANativeWindow *window)` | `void(*` The drawing window for this native activity is going to be destroyed. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a2680b60d06ca7cab177f0759a859cfae)(GameActivity *activity, ANativeWindow *window)` | `void(*` The drawing window for this native activity needs to be redrawn. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1aa599a1c89145e3e73810d8fdb845719c)(GameActivity *activity, ANativeWindow *window, int32_t newWidth, int32_t newHeight)` | `void(*` The drawing window for this native activity has been resized. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a821b651a9bc79b3e7d6814ae3abd595f)(GameActivity *activity)` | `void(*` [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has paused. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a2d54d996ef20d5cca17834378de291c0)(GameActivity *activity)` | `void(*` [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has resumed. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1adbb4553fae371267da7b40460580edf5)(GameActivity *activity, SaveInstanceStateRecallback recallback, void *context)` | `void(*` The framework is asking [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) to save its current instance state. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a30064a9388915f12469e9fa270bed561)(GameActivity *activity)` | `void(*` [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has started. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a5648941a541b3b42da38ab12c739949f)(GameActivity *activity)` | `void(*` [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has stopped. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1abac9e92a071c990cae46b081d430c590)(GameActivity *activity, const GameTextInputState *state)` | `void(*` Callback called for every soft-keyboard text input event. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1ad173ef18e595ccac12fc9c887b0311b4)(GameActivity *activity, const GameActivityMotionEvent *event)` | `bool(*` Callback called for every MotionEvent done on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1afcf5b1cd4efbe600352d165378a3f9e1)(GameActivity *activity, int level)` | `void(*` The system is running low on memory. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1a6a5198184d0ebca91c6153a78fb2276b)(GameActivity *activity, bool hasFocus)` | `void(*` Focus has changed in this [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity)'s window. |
| `https://developer.android.com/reference/games/game-activity/struct/game-activity-callbacks#struct_game_activity_callbacks_1aeaf05dde4f686ef7f8fc46ede64923b0)(GameActivity *activity)` | `void(*` Callback called when WindowInsets of the main app window have changed. |

## Public attributes

### onConfigurationChanged

```scdoc
void(* GameActivityCallbacks::onConfigurationChanged)(GameActivity *activity)
```
The current device AConfiguration has changed.

The new configuration can be retrieved from assetManager.

### onDestroy

```scdoc
void(* GameActivityCallbacks::onDestroy)(GameActivity *activity)
```
[GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) is being destroyed.

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

### onKeyDown

```gdscript
bool(* GameActivityCallbacks::onKeyDown)(GameActivity *activity, const GameActivityKeyEvent *event)
```
Callback called for every key down event on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView.

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

### onKeyUp

```gdscript
bool(* GameActivityCallbacks::onKeyUp)(GameActivity *activity, const GameActivityKeyEvent *event)
```
Callback called for every key up event on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView.

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

### onNativeWindowCreated

```scdoc
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

```scdoc
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

```scdoc
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

```scdoc
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

```scdoc
void(* GameActivityCallbacks::onPause)(GameActivity *activity)
```
[GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has paused.

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

### onResume

```scdoc
void(* GameActivityCallbacks::onResume)(GameActivity *activity)
```
[GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has resumed.

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

### onSaveInstanceState

```scdoc
void(* GameActivityCallbacks::onSaveInstanceState)(GameActivity *activity, SaveInstanceStateRecallback recallback, void *context)
```
The framework is asking [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) 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

```scdoc
void(* GameActivityCallbacks::onStart)(GameActivity *activity)
```
[GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has started.

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

### onStop

```scdoc
void(* GameActivityCallbacks::onStop)(GameActivity *activity)
```
[GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) has stopped.

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

### onTextInputEvent

```gdscript
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

```gdscript
bool(* GameActivityCallbacks::onTouchEvent)(GameActivity *activity, const GameActivityMotionEvent *event)
```
Callback called for every MotionEvent done on the [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity) SurfaceView.

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

### onTrimMemory

```scdoc
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

```scdoc
void(* GameActivityCallbacks::onWindowFocusChanged)(GameActivity *activity, bool hasFocus)
```
Focus has changed in this [GameActivity](https://developer.android.com/reference/games/game-activity/struct/game-activity#struct_game_activity)'s window.

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

### onWindowInsetsChanged

```scdoc
void(* GameActivityCallbacks::onWindowInsetsChanged)(GameActivity *activity)
```
Callback called when WindowInsets of the main app window have changed.

Call GameActivity_getWindowInsets to retrieve the insets themselves.