From 823804c0bf07be9002a110c1f1a716705445e78f Mon Sep 17 00:00:00 2001 From: MrPiglr Date: Thu, 12 Feb 2026 13:20:26 -0700 Subject: [PATCH] fix(webview): add 1s delay and aggressive cache clear to fix black screen race condition --- .../main/java/com/aethex/os/MainActivity.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/aethex/os/MainActivity.java b/android/app/src/main/java/com/aethex/os/MainActivity.java index 56e64a7..77d59ea 100644 --- a/android/app/src/main/java/com/aethex/os/MainActivity.java +++ b/android/app/src/main/java/com/aethex/os/MainActivity.java @@ -12,19 +12,25 @@ import com.getcapacitor.BridgeActivity; import android.util.Log; +import android.os.Handler; + public class MainActivity extends BridgeActivity { - // Using onStart to hijack the process immediately after bridge init @Override public void onStart() { super.onStart(); if (this.bridge != null && this.bridge.getWebView() != null) { - loadCustomUrl(); + // Delay loading to ensure WebView is ready and avoid race conditions + new Handler().postDelayed(this::loadCustomUrl, 1000); } } private void loadCustomUrl() { WebView webView = this.bridge.getWebView(); + + runOnUiThread(() -> { + Toast.makeText(MainActivity.this, "Resetting & Loading...", Toast.LENGTH_SHORT).show(); + }); // Set WebView background to BLACK webView.setBackgroundColor(0xFF000000); @@ -60,16 +66,13 @@ public class MainActivity extends BridgeActivity { } }); - // Clear cache to ensure we aren't loading stale files + // NUCLEAR CACHE CLEAR webView.clearCache(true); webView.clearHistory(); + webView.clearFormData(); + webView.clearSslPreferences(); // Force load our local test file - // webView.loadUrl("file:///android_asset/public/test.html"); - - // SWITCH TO REAL APP - // Using "file:///android_asset/public/" base path which matches the physical structure - // AND ensuring we load index.html webView.loadUrl("file:///android_asset/public/test_red.html"); } }