mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-08 14:56:12 -04:00
Android: Fix after activity is recreated, you can't use on screen keyboard or go ingame anymore
This commit is contained in:
parent
c21b7a93f3
commit
9b9cc97336
@ -193,6 +193,8 @@ public class MainActivity extends Activity {
|
|||||||
HACK_avoidFileUriExposedErrors();
|
HACK_avoidFileUriExposedErrors();
|
||||||
|
|
||||||
if (!gameRunning) startGameAsync();
|
if (!gameRunning) startGameAsync();
|
||||||
|
// TODO rethink to avoid this
|
||||||
|
if (gameRunning) updateInstance();
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +384,7 @@ public class MainActivity extends Activity {
|
|||||||
native void processOnLowMemory();
|
native void processOnLowMemory();
|
||||||
|
|
||||||
native void runGameAsync();
|
native void runGameAsync();
|
||||||
|
native void updateInstance();
|
||||||
|
|
||||||
// ======================================
|
// ======================================
|
||||||
// --------------- VIEWS ----------------
|
// --------------- VIEWS ----------------
|
||||||
|
@ -198,4 +198,45 @@ void JavaCall_String_String(const char* name, const cc_string* arg, cc_string* d
|
|||||||
ReturnString(env, obj, dst);
|
ReturnString(env, obj, dst);
|
||||||
(*env)->DeleteLocalRef(env, args[0].l);
|
(*env)->DeleteLocalRef(env, args[0].l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*----------------------------------------------------Initialisation-------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
extern void android_main(void);
|
||||||
|
static void JNICALL java_updateInstance(JNIEnv* env, jobject instance) {
|
||||||
|
Platform_LogConst("App instance updated!");
|
||||||
|
App_Instance = (*env)->NewGlobalRef(env, instance);
|
||||||
|
/* TODO: Do we actually need to remove that global ref later? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called eventually by the activity java class to actually start the game */
|
||||||
|
static void JNICALL java_runGameAsync(JNIEnv* env, jobject instance) {
|
||||||
|
void* thread;
|
||||||
|
java_updateInstance(env, instance);
|
||||||
|
|
||||||
|
Platform_LogConst("Running game async!");
|
||||||
|
/* The game must be run on a separate thread, as blocking the */
|
||||||
|
/* main UI thread will cause a 'App not responding..' messagebox */
|
||||||
|
thread = Thread_Start(android_main);
|
||||||
|
Thread_Detach(thread);
|
||||||
|
}
|
||||||
|
static const JNINativeMethod methods[] = {
|
||||||
|
{ "updateInstance", "()V", java_updateInstance },
|
||||||
|
{ "runGameAsync", "()V", java_runGameAsync }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* This method is automatically called by the Java VM when the */
|
||||||
|
/* activity java class calls 'System.loadLibrary("classicube");' */
|
||||||
|
CC_API jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||||
|
jclass klass;
|
||||||
|
JNIEnv* env;
|
||||||
|
VM_Ptr = vm;
|
||||||
|
JavaGetCurrentEnv(env);
|
||||||
|
|
||||||
|
klass = (*env)->FindClass(env, "com/classicube/MainActivity");
|
||||||
|
App_Class = (*env)->NewGlobalRef(env, klass);
|
||||||
|
JavaRegisterNatives(env, methods);
|
||||||
|
return JNI_VERSION_1_4;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -123,42 +123,13 @@ int main_real(int argc, char** argv) {
|
|||||||
#elif defined CC_BUILD_ANDROID
|
#elif defined CC_BUILD_ANDROID
|
||||||
/* ClassiCube is just a native library on android, */
|
/* ClassiCube is just a native library on android, */
|
||||||
/* unlike other platforms where it is the executable. */
|
/* unlike other platforms where it is the executable. */
|
||||||
/* (activity java class is responsible for kickstarting the game) */
|
/* (activity java class is responsible for kickstarting the game,
|
||||||
static void android_main(void) {
|
see Platform_Android.c for the code that actually calls this) */
|
||||||
|
void android_main(void) {
|
||||||
Platform_LogConst("Main loop started!");
|
Platform_LogConst("Main loop started!");
|
||||||
SetupProgram(0, NULL);
|
SetupProgram(0, NULL);
|
||||||
for (;;) { RunProgram(0, NULL); }
|
for (;;) { RunProgram(0, NULL); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called eventually by the activity java class to actually start the game */
|
|
||||||
static void JNICALL java_runGameAsync(JNIEnv* env, jobject instance) {
|
|
||||||
void* thread;
|
|
||||||
App_Instance = (*env)->NewGlobalRef(env, instance);
|
|
||||||
/* TODO: Do we actually need to remove that global ref later? */
|
|
||||||
|
|
||||||
Platform_LogConst("Running game async!");
|
|
||||||
/* The game must be run on a separate thread, as blocking the */
|
|
||||||
/* main UI thread will cause a 'App not responding..' messagebox */
|
|
||||||
thread = Thread_Start(android_main);
|
|
||||||
Thread_Detach(thread);
|
|
||||||
}
|
|
||||||
static const JNINativeMethod methods[] = {
|
|
||||||
{ "runGameAsync", "()V", java_runGameAsync }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This method is automatically called by the Java VM when the */
|
|
||||||
/* activity java class calls 'System.loadLibrary("classicube");' */
|
|
||||||
CC_API jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|
||||||
jclass klass;
|
|
||||||
JNIEnv* env;
|
|
||||||
VM_Ptr = vm;
|
|
||||||
JavaGetCurrentEnv(env);
|
|
||||||
|
|
||||||
klass = (*env)->FindClass(env, "com/classicube/MainActivity");
|
|
||||||
App_Class = (*env)->NewGlobalRef(env, klass);
|
|
||||||
JavaRegisterNatives(env, methods);
|
|
||||||
return JNI_VERSION_1_4;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
/* NOTE: main_real is used for when compiling with MingW without linking to startup files. */
|
/* NOTE: main_real is used for when compiling with MingW without linking to startup files. */
|
||||||
/* Normally, the final code produced for "main" is our "main" combined with crt's main */
|
/* Normally, the final code produced for "main" is our "main" combined with crt's main */
|
||||||
|
@ -261,7 +261,7 @@ void Window_Init(void) {
|
|||||||
DisplayInfo.ScaleY = JavaICall_Float(env, JAVA_getDpiY, NULL);
|
DisplayInfo.ScaleY = JavaICall_Float(env, JAVA_getDpiY, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Window_RemakeSurface(void) {
|
static void RemakeWindowSurface(void) {
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
JavaGetCurrentEnv(env);
|
JavaGetCurrentEnv(env);
|
||||||
winCreated = false;
|
winCreated = false;
|
||||||
@ -272,6 +272,7 @@ static void Window_RemakeSurface(void) {
|
|||||||
Platform_LogConst("Entering wait for window exist loop..");
|
Platform_LogConst("Entering wait for window exist loop..");
|
||||||
|
|
||||||
/* Loop until window gets created by main UI thread */
|
/* Loop until window gets created by main UI thread */
|
||||||
|
/* (i.e. until processSurfaceCreated is received) */
|
||||||
while (!winCreated) {
|
while (!winCreated) {
|
||||||
Window_ProcessEvents();
|
Window_ProcessEvents();
|
||||||
Thread_Sleep(10);
|
Thread_Sleep(10);
|
||||||
@ -282,8 +283,7 @@ static void Window_RemakeSurface(void) {
|
|||||||
|
|
||||||
static void DoCreateWindow(void) {
|
static void DoCreateWindow(void) {
|
||||||
WindowInfo.Exists = true;
|
WindowInfo.Exists = true;
|
||||||
/* actual window creation is done when processSurfaceCreated is received */
|
RemakeWindowSurface();
|
||||||
Window_RemakeSurface();
|
|
||||||
/* always start as fullscreen */
|
/* always start as fullscreen */
|
||||||
Window_EnterFullscreen();
|
Window_EnterFullscreen();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user