changeset 2511:0945d0428dfe

Android: New workaround for activity relaunch at startup. This workaround should prevent complete startup failure, but it does institute a 10 second delay, to see if we get called again. Hoping one day to figure out why this is happening and remove this completely, but if we can't, this delay can be used to show a splash screen in the future.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 07 May 2021 10:29:47 +0000
parents f54051c3f2a5
children e57765c7a437
files android/dw.cpp
diffstat 1 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/android/dw.cpp	Fri May 07 09:35:14 2021 +0000
+++ b/android/dw.cpp	Fri May 07 10:29:47 2021 +0000
@@ -87,16 +87,31 @@
 JNIEXPORT void JNICALL
 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path)
 {
-    static int runcount = 0;
+    static HEV startup = 0;
 
     /* Safety check to prevent multiple initializations... */
-#if defined(__arm__) || defined(__aarch64__)
-    if(runcount == 0)
-#else
-    if(runcount == 1)
-#endif
+    if(startup)
+    {
+        /* If we are called a second time.. post the event...
+         * so we stop waiting.
+         */
+        dw_event_post(startup);
+        return;
+    }
+    else
     {
-        char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL));
+        char *arg;
+
+        /* Wait for a short while to see if we get called again...
+         * if we get called again we will be posted, if not...
+         * just wait for the timer to expire.
+         */
+        startup = dw_event_new();
+        /* Wait for 10 seconds to see if we get called again */
+        dw_event_wait(startup, 10000);
+
+        /* Continue after being posted or after our timeout */
+        arg = strdup(env->GetStringUTFChars((jstring) path, NULL));
 
         /* Save our class object pointer for later */
         _dw_obj = env->NewGlobalRef(obj);
@@ -111,7 +126,6 @@
         /* Launch the new thread to execute dwmain() */
         dw_thread_new((void *) _dw_main_launch, arg, 0);
     }
-    runcount++;
 }
 
 typedef struct _sighandler