@@ -56,11 +56,9 @@ void AndroidCommons::forcePublishActivity() {
5656 // 2) Re-publish to Qt (if available in your Qt build)
5757 // Safe no-op if it's already the same:
5858 QJniObject::callStaticMethod<void >(
59- " org/qtproject/qt/android/QtNative" ,
60- " setActivity" ,
61- " (Landroid/app/Activity;)V" ,
62- activity.object <jobject>());
63- return true ;
59+ " org/qtproject/qt/android/QtNative" , " setActivity" ,
60+ " (Landroid/app/Activity;)V" , activity.object <jobject>());
61+ return true ;
6462 });
6563 fut.waitForFinished ();
6664}
@@ -151,11 +149,9 @@ void AndroidCommons::launchPlayStore() {
151149 appActivity.object ());
152150}
153151
154-
155-
156152bool AndroidCommons::clearPendingJavaException (const char * where) {
157153 QJniEnvironment env;
158- if (!env->ExceptionCheck ()){
154+ if (!env->ExceptionCheck ()) {
159155 logger.info () << " No pending exception at" << where;
160156 return false ;
161157 }
@@ -165,9 +161,9 @@ bool AndroidCommons::clearPendingJavaException(const char* where) {
165161 return true ;
166162};
167163
168-
169164// static
170- void AndroidCommons::runWhenUiViewConstructible (std::function<void ()> fn, int retryMs) {
165+ void AndroidCommons::runWhenUiViewConstructible (std::function<void ()> fn,
166+ int retryMs) {
171167 using QAA = QNativeInterface::QAndroidApplication;
172168 auto attempt = [fn = std::move (fn), retryMs]() mutable {
173169 // Do the probe on the Android UI thread
@@ -180,20 +176,30 @@ void AndroidCommons::runWhenUiViewConstructible(std::function<void()> fn, int re
180176
181177 // 2) Actually try to construct a View with that Context
182178 QJniEnvironment env;
183- QJniObject dummyView (" android/view/View" , " (Landroid/content/Context;)V" , ctx.object ());
184- if (env->ExceptionCheck ()) { env->ExceptionDescribe (); env->ExceptionClear (); return false ; }
179+ QJniObject dummyView (" android/view/View" , " (Landroid/content/Context;)V" ,
180+ ctx.object ());
181+ if (env->ExceptionCheck ()) {
182+ env->ExceptionDescribe ();
183+ env->ExceptionClear ();
184+ return false ;
185+ }
185186
186187 if (clearPendingJavaException (" gate-exit(UI)" )) return false ;
187188
188189 // Success — run the work on the Qt thread
189- QMetaObject::invokeMethod (qApp, [fn = std::move (fn)]() mutable { fn (); }, Qt::QueuedConnection);
190+ QMetaObject::invokeMethod (
191+ qApp, [fn = std::move (fn)]() mutable { fn (); }, Qt::QueuedConnection);
190192 return true ;
191193 }).then ([retryMs, fn = std::move (fn)](QFuture<QVariant> f) mutable {
192- const bool ok = f.isValid () && f.result ().isValid () && f.result ().toBool ();
193- if (!ok) QTimer::singleShot (retryMs, qApp, [fn = std::move (fn), retryMs]() mutable {
194- AndroidCommons::runWhenUiViewConstructible (std::move (fn), retryMs);
195- });
194+ const bool ok =
195+ f.isValid () && f.result ().isValid () && f.result ().toBool ();
196+ if (!ok)
197+ QTimer::singleShot (retryMs, qApp,
198+ [fn = std::move (fn), retryMs]() mutable {
199+ AndroidCommons::runWhenUiViewConstructible (
200+ std::move (fn), retryMs);
201+ });
196202 });
197203 };
198204 QTimer::singleShot (0 , qApp, attempt);
199- }
205+ }
0 commit comments