diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index e9faa6b..1917e7e 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -39,6 +39,7 @@ struct GamestateResources; #include <allegro5/allegro_ttf.h> #include <allegro5/allegro_video.h> #ifdef ALLEGRO_ANDROID +#define ALLEGRO_UNSTABLE #include <allegro5/allegro_android.h> #endif #ifdef __EMSCRIPTEN__ diff --git a/src/utils.c b/src/utils.c index e5f170b..d77b098 100644 --- a/src/utils.c +++ b/src/utils.c @@ -528,3 +528,19 @@ SYMBOL_EXPORT char* PunchNumber(struct Game* game, char* text, char ch, int numb }; return AddGarbage(game, txt); } + +SYMBOL_EXPORT void QuitGame(struct Game* game, bool allow_pausing) { +#ifdef ALLEGRO_ANDROID + if (allow_pausing) { + JNIEnv* env = al_android_get_jni_env(); + jclass class_id = (*env)->GetObjectClass(env, al_android_get_activity()); + jmethodID method_id = (*env)->GetMethodID(env, class_id, "moveTaskToBack", + "(Z)Z"); + jvalue jdata; + jdata.z = JNI_TRUE; + (*env)->CallBooleanMethodA(env, al_android_get_activity(), method_id, &jdata); + return; + } +#endif + UnloadAllGamestates(game); +} diff --git a/src/utils.h b/src/utils.h index f083b18..7e5d412 100644 --- a/src/utils.h +++ b/src/utils.h @@ -92,4 +92,7 @@ void DisableCompositor(struct Game* game); char* PunchNumber(struct Game* game, char* text, char ch, int number); +/*! \brief Quits the game. On platforms that allow it, brings the game to the background without quiting if <allow_pausing> is true. */ +void QuitGame(struct Game* game, bool allow_pausing); + #endif