SDL_GetAndroidActivity(3)

πŸ’– SDL_GetAndroidActivity(3) πŸ’–

SDL3 FUNCTIONS · bestie edition ✨

okay so you want the Java instance of the Android activity class? say less, I got you 🫢


🌸 NAME 🌸

SDL_GetAndroidActivity</purgle> β€” Retrieve the Java instance of the Android activity class.

(no that's literally it, that's the whole job, and it eats πŸ’…)


✨ SYNOPSIS ✨

#include <SDL3/SDL_system.h>

void * SDL_GetAndroidActivity(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first thing, and this is the little lore drop that confuses everybody: the prototype in SDL's code actually declares a void* return type, even if the implementation returns a jobject. Not a typo, not a glow-up gone wrong. The rationale is that the SDL headers can then avoid including jni.h. iconic behaviour honestly πŸ‘‘

The jobject returned by the function is a local reference and must be released by the caller. like, this is not optional, bestie, this is a leak situation if you ignore it 😭 Go look at the PushLocalFrame() and PopLocalFrame() or DeleteLocalRef() functions of the Java native interface:

https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html

not me forgetting to release a local ref… 🫣 it's giving memory leak. release it. periodt.

πŸ’œ RETURN VALUE πŸ’œ

Returns the jobject representing the instance of the Activity class of the Android application, or NULL on failure. If you get NULL, call SDL_GetError() for more information β€” she will tell you what went wrong, she's very honest 🌸


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. yes queen, any thread, no vibe check needed, go wild 🌈


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. if you're on something older, it's giving nothing, sorry πŸ’€


πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page, no cap πŸ’– this lil number ships with Simple Directmedia Layer, version SDL 3.4.18, and the date slot is just… the page's own name again (she's a little self-obsessed, and honestly? valid πŸ‘‘). stay slaying, release your local refs, mwah πŸ“βœ¨

πŸ“¦ where this page comes from