fix(webview): add 1s delay and aggressive cache clear to fix black screen race condition

This commit is contained in:
MrPiglr 2026-02-12 13:20:26 -07:00
parent 68d2bccb50
commit 823804c0bf

View file

@ -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");
}
}